using yii rest api with default URL GET format rather than PATH format - yii

I have a problem with a yii rest api. I configured it to work following the tutorial on the yii framework page, but after that i realised that my api works BUT NOT some big PORTIONS of my PAGE since it is based on the GET URL format rather than PATH which is required by the rest api.
So in my config/main.php i have the following setting
'urlManager' => array (
'urlFormat' => 'path',
'rules' => array (
'student/<id:\d+>/<title:.*?>' => 'student/view',
'students/<tag:.*?>' => 'student/index',
array (
'apistudent/register',
'pattern' => 'api/<model:\w+>',
'verb' => 'POST'
),
'<controller:\w+>/<action:\w+>' => '<controller>/<action>'
)
),
I also have a controller named ApiStudentController with a method called actionRegister().
So as already stated the api works normally but my page does not since i set the urlFormat to be 'path'.
The question is... how can i use the rest api but without the PATH url format and rather the default get url format (index.php?r=apistudent/register)?

I too faced the same problem in yii 1.x. I just need my API controller alone in old GET format rather than in PATH format (as i changed my websites URLs in PATH format). Finally i got it worked with a small hack in script file
$app = Yii::createWebApplication($env->configWeb); //store the app
//Change the UrlFormat for urlManager to get if a get request is given instead of a path format one.
if (isset($_GET['r'])) {
Yii::app()->urlManager->setUrlFormat('get');
}
$app->run(); //run the app
I dont know whether this solves your problem. But this can give you an idea. Happy Coding!

Related

How to pass parameters to script file under shopify using php?

I want to pass parameters to script.js file that is included in the script_tags.json file of shopify.
I have mentioned below the code to add script file in script_tags.json file.
$script_array = array(
'script_tag' => array(
'event' => 'onload',
'src' => 'https://www.softwareprive.com/shopifyapps/ngdesk/js/script.js'
)
);
$scriptTag = shopify_call($token, $shop, "/admin/api/2019-10/script_tags.json", $script_array, 'POST');
You don't pass parameters to scripts. They execute after the DOM has loaded. So your script code can access data that was prepared for your script to use. That would mean providing some Liquid and/or other theme code. Otherwise, you are left with doing scripting by introspection of the DOM and hoping you sniff out the gold you are looking for.

Which Magento Soap V2 method should I use for external links?

I am working on a script that imports all product information from a Magento 1.9.3.1 website.
I cant seem to find a method which allows me to get the external links data which is associated with every product.
(See screenshot)
Does anyone know which method I need to use?
A list of methods can be found here:
http://devdocs.magento.com/guides/m1x/api/soap/introduction.html#Introduction-APIMethods
I think I have used all catalog related methods but none of them seem to return the data I need.
You can use this method: http://devdocs.magento.com/guides/m1x/api/soap/catalog/catalogProduct/catalog_product.update.html
From your screenshots, these look like custom attributes. Obtain their codes from Catalog > Attributes > Manage Attributes. Then, in the catalog_product.update call, include them in additonal_attributes as an array or arrays.
Example:
'additional_attributes' => array(
array('key' => 'ready_link', 'value'=> '...'),
array('key' => 'itunes_link', 'value'=> '...'),
)

Catalyst Framework HTML::Formhandler shows vadiate errors, when using HTML GET to Access the Site

I have an HTML::Formhandler Form on my Catalyst Framework. The Problem is, that I get an error-message in the Form, when I load the Form-Site with an HTML GET-Requelst.
has_field 'name' => (type => 'Text', required => 1);
So if I load the Site via: localhost:3000/form no errors occurs.
But if I load the Site via localhost:3000/form?foo=bar the form says: "Field required".
Any Idea how to solve this?
By default HTML::FormHandler determines whether to validate a from by the existence of params. If you don't want to do that, you can use the 'posted' flag in the ->process statement. If you want the query parameter to provide a default to the form, you need to pass it in via an init_object: init_object => { foo => bar }.

using url manager in yii to change url to seo friendly

How can I convert these URL to SEO friendly URL I tried Url manager in yii but didn't get the proper result is there any good tutorial regarding url manager
http://localhost/nbnd/search/city?city=new+york
http://localhost/nbnd/search/manualsearch?tosearch=Hotel+%26+Restaurants+&city=New+york&yt0=Search&searchtype=
I tried to the following setting in url manager
'<controller:\w+>/<action:\w+>/<city:\d>'=>'<controller>/<action>',
which works with url http://localhost/nbnd/search/city/city/Delhi
I wish to reduce this url to http://localhost/nbnd/search/city/Delhi
and the link I generating in my view is <?php echo CHtml::link(CHtml::encode($data->city), array('/search/city', 'city'=>$data->city)); ?>
This generates link as http://localhost/nbnd/search/city?city=Delhi
How can I convert that link to like http://localhost/nbnd/search/city/Delhi
The rule should be (to remove the extra city, which is the GET parameter name):
'<controller:\w+>/<action:\w+>/<city:\w+>'=>'<controller>/<action>', // not city:\d, since Delhi is a string, not digit
So the rule should be able to match the parameter name, incase you had foo/Delhi, you'd use <foo:\w+>.
And to remove the ? use appendParams of CUrlManager, (in your urlManager config):
'urlManager'=>array(
'urlFormat'=>'path',
'appendParams'=>true,
// ... more properties ...
'rules'=>array(
'<controller:\w+>/<action:\w+>/<city:\w+>'=>'<controller>/<action>',
// ... more rules ...
)
)
When appendParams
is true, GET parameters will be appended to the path info and separate from each other using slashes.
Update: Incase you have more than one parameter being passed to the action i.e:
http://localhost/nbnd/search/manualsearch/Delhi?tosearch=restaurants
Use a /* at the end of the rule:
'<controller:\w+>/<action:\w+>/<city:\w+>/*'=>'<controller>/<action>'
To get urls of form:
http://localhost/nbnd/search/manualsearch/Delhi/tosearch/restaurants
In Yii we can create urls dynamically For eg.
$url=$this->createUrl($route,$params);
$route='post/read'.
$params=array('id'=>100)
we would obtain the following URL:
/index.php?r=post/read&id=100
To change the URL format, we should configure the urlManager application component so that createUrl can automatically switch to the new format and the application can properly understand the new URLs:
array(
......
'components'=>array(
......
'urlManager'=>array(
'urlFormat'=>'path',
),
),
);
WE will obtain this
/index.php/post/read/id/100
You can refer this link for user friendly urls in yii
http://www.yiiframework.com/doc/guide/1.1/en/topics.url

How do Media Views work in cakephp?

I have arranged a file upload to happen on my application relative address: webroot/files
Now I need to force download on the uploaded files. After some googling and trying like most of the suggestions from this post I figured out the correct way to do this is using cakephps Media Views
What I have:
Main site with a table of records. Model -> Record; Table -> records;
These records have a primary key record_id.
In my database I have a Table -> files; Model -> File;
These files have a foreign key record_id and a field 'url' with the relative path to it's location.
After creating a record with files, the files are correctly uploaded to the folder, which relative address is e.g. webroot/files/record_name/file and the tables in database are correctly updated.
What I want to do:
After doubleclicking on one table row open a modal dialog with the information about the record. (done)
In this modal dialog I want to display links that will force download on these files.
I tried many variations of this:
//the retrieving of data after debug looks fine//
$this->loadModel('File');
$files = $this->File->find('list', array(
'conditions'=>array('File.record_id'=>$record_id),
'fields' => array('File.Name', 'File.Url');
))
//actual display of url
foreach($files as $file_name => $file_url) {
echo $this->Html->link($file_name, $file_url);
}
The resulting link looks exactly the way James Revillini presented
This is my actual question
Since that issue was not entirely solved, I thought it would be helpful not only for me, but for anybody who's searching for a quick solution for this problem to see a quick demonstration of how Media-views work. I have no idea where to move after making a dynamic download function:
public function download($name, $path) {
$this->viewClass = 'Media';
$params = array(
'id' => $name,
'name' => $name,
'download' => true,
'path' => $path
);
$this->set($params);
}
Point the link in the modal dialog for the resource to the download() function.
Pass the Record.id to that function. In it find the file and auto-render it.
It should work.