Yii dir separator // - yii

I have seen this line of code in Yii when playing with layout:
<?php $this->beginContent('//layouts/main'); ?>
Normally I only see single forward slash, but now double. And, when I remove one forward slash in the above code, the output display didn't change at all.
So, could you tell me why Yii using double slashes instead of single slash? And does them return the same resutl?
Thank you.

In Yii context and this example //layouts/main will be rendered to protected/views/layouts/main.php. It's path to your layouts folder.
You want to use double slashes if there is non-default layout directory.
For example if you have two folders layouts and layouts-fancy under protected/views/{here}
You can switch to fancy layouts by prefix path with '//'. By default Yii will be using layouts (see http://www.yiiframework.com/doc/guide/1.1/en/basics.view#layout).
For better testing create new layout protected/views/layout-fancy/main.php and add variable public $layout = '//layout-fancy/main.php'; to your base Controller.php and see what happen.

Related

Joomla remove scripts and css loaded by extensions

Using Joomla 2.5 and I have a dual instance of jquery running on one of my pages that I would like to get rid of. I tried using,
$document->getHeadData();
to no avail. The array does not contain the js files I need to unset. So what is my best option to find the js file and unload it? It seems to be getting loaded later in the page rendering process and then repopulating the head data. I am using a yoo theme template with some other extensions loaded.
I would like to avoid hard coding the template/extension files if possible since that would unload it on every page and I only want to unload it for one page.
Try this,
<?php
//get the array containing all the script declarations
$document = JFactory::getDocument();
$headData = $document->getHeadData();
$scripts = $headData['scripts'];
unset($scripts['/media/system/js/mootools-core.js']);
unset($scripts['/media/system/js/mootools-more.js']);
$headData['scripts'] = $scripts;
$document->setHeadData($headData);
?>
Or
<?php unset($this->_scripts['/media/system/js/mootools-core.js']); ?>
then simply use $document->addScript() for adding new js files.
hope its works..

Multiple GET parameters in UrlManager

I am using Yii 1.1.14.
I want to convert
http://website.com/controller/action?param1=value1&param2=value2
to
http://website.com/value1/value2
How to do this in urlManager?
First, check this to hide index.php:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x
Then, the route in config.php should be like this:
'<param1:\w+>/<param2:\w+>'=>'mycontroller/myaction',
The method myaction should accept $param1 and $param2 in its constructor to be passed automatically by Yii.
This would make your app unable to look for other controllers, because that rule will accept every route with 2 words separated by /

New blank page in Zen-Cart

How can I create a new blank page in zen-cart without applying the template.
I want to create a page that will result only a JSON data...
Thanks in advance
Create a php file in your store directory. In that file, if you want to use ZenCart functions you can include them, like so:
<?php
include "includes/application_top.php";
set headers for mime type
set headers for not caching
YOUR CODE
echo $json;
// below is optional if you didn't create/edit session
include "includes/application_bottom.php";

Completely custom path with YII?

I have various products with their own set paths. Eg:
electronics/mp3-players/sony-hg122
fitness/devices/gymboss
If want to be able to access URLs in this format. For example:
http://www.mysite.com/fitness/devices/gymboss
http://www.mysite.com/electronics/mp3-players/sony-hg122
My strategy was to override the "init" function of the SiteController in order to catch the paths and then direct it to my own implementation of a render function. However, this doesn't allow me to catch the path.
Am I going about it the wrong way? What would be the correct strategy to do this?
** EDIT **
I figure I have to make use of the URL manager. But how do I dynamically add path formats if they are all custom in a database?
Eskimo's setup is a good solid approach for most Yii systems. However, for yours, I would suggest creating a custom UrlRule to query your database:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-custom-url-rule-classes
Note: the URL rules are parsed on every single Yii request, so be careful in there. If you aren't efficient, you can rapidly slow down your site. By default rules are cached (if you have a cache setup), but I don't know if that applies to dynamic DB rules (I would think not).
In your URL manager (protected/config/main.php), Set urlFormat to path (and toptionally set showScriptName to false (this hides the index.php part of the URL))
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName'=>false,
Next, in your rules, you could setup something like:
catalogue/<category_url:.+>/<product_url:.+> => product/view,
So what this does is route and request with a structure like catalogue/electronics/ipods to the ProductController actionView. You can then access the category_url and product_url portions of the URL like so:
$_GET['category_url'];
$_GET['product_url'];
How this rule works is, any URL which starts with the word catalogue (directly after your domain name) which is followed by another word (category_url), and another word (product_url), will be directed to that controller/action.
You will notice that in my example I am preceding the category and product with the word catalogue. Obviously you could replace this with whatever you prefer or leave it out all together. The reason I have put it in is, consider the following URL:
http://mywebsite.com/site/about
If you left out the 'catalogue' portion of the URL and defined your rule only as:
<category_url:.+>/<product_url:.+> => product/view,
the URL Manager would see the site portion of the URL as the category_url value, and the about portion as the product_url. To prevent this you can either have the catalogue protion of the URL, or define rules for the non catalogue pages (ie; define a rule for site/about)
Rules are interpreted top to bottom, and only the first rule is matched. Obviously you can add as many rules as you need for as many different URL structures as you need.
I hope this gets you on the right path, feel free to comment with any questions or clarifications you need

Access the http_images_path constant in a SASS file

I'm trying to write a #mixin for High Density Display like the iPhone 4+ Retina Display. Therefore I want to automatically append "#2x" as a suffix to the images filenames.
Since image-url() throws back the whole path I can't append the suffix. Not I'm trying to access the Image-Path I've set in the config to patch the URL together by myself.
Like:
background: $color url("#{$http_images_path}"+"#{$image-name}"+"#2x"+"#{$image-extension}") $x $y no-repeat
But #{$http_images_path} is undefined. Is there a way to access it? I don't really want to define the image-path seperatly since it would make the config quite unnecessary.
Even nicer would be if I could split the return of image-url() before the "." of the extension and add "#2x", because I wouldn't need to define the extension separately. I've tried to use Ruby in the sass file like puts "test" but it didn't work. So I'm not sure if theres a way to split strings with sass.
Do you guys have some good ideas?
Thanks!
Alex
You can concatenate your image name inside image_url()
config.rb
images_dir = "images"
http_images_path = "/your/path"
screen.sass
$image-name: "asset"
$image-extension: ".png"
.class
background-image: image_url($image-name + "#2x" + $image-extension)
screen.css
/* line 4, ../sass/screen.sass */
.class {
background-image: url('/your/path/asset#2x.png?1327210853');
}
If you want to go the route of splitting the file name and inserting #2x, you'll have to create an extension where ruby does that for you. You could use my Compass extension as a starting point.