I am new to Yii and i would like to know how to install extensions, i.e the EHttpClient.
I have already searched the Internet but haven't found a good How-To.
Thanks for your instructions.
You don't need to install the extension u just extract the extension to protected/extension folder thats it
A better explanation could be made if an example was given, so here is an example.
If you wanted to use Bootstrap, you need to download it and place that folder into de protected/extensions.
Then, in your config/main.php, do this.
Basicaly, you need to tell Yii to use that extension in the main.php.
In this case, it is just:
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
//note this is **outside** of *return array(*
return array(
....
'theme'=>'bootstrap',
'modules'=>array(
'gii'=>array(
'generatorPaths'=>array(
'bootstrap.gii',
),
),
),
'components'=>array(
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
),
....
);
Also, in Bootstrap's particular case, in your layout, you need to register the CSS and JS of the extension with:
Yii::app()->bootstrap->register();
That is is all I believe.
Related
I did this:
I downloaded a zip from OpenCart website and put it in xampp/htdocs/mywebsite. I need PhpStorm to autocomplete methods of OpenCart classes but none are recognized I think. And this is not only for OpenCart: I have the same issue with WordPress as well.
Edit: check this screenshot
I want this:
I want external classes to support autocomplete but I don't know what to do.
Solved
So after a year and half practicing opencart, i can now answer this question. In opencart we have a folder called 'model'. there are files in this folder which you can call in any 'controller' you want. And this models are generated dynamicly. Because of that you cant trace them in IDE, like click on them and see the exact file. Thats why opencart sucks.
I am working in the JetBrains PhpStorm IDE and I use the "Mark directory as" to mark my public resource folder.
This is working perfect with the public resources.
I was wondering if thats also possible for my App views, I already marked my "views" directory as Resource but that didn't do anything.
So to be clear I mean, Now I have to type the path myself
I want the path to autocomplete with the views directory as the root
protected function view($view, $data = [])
{
require_once "../app/views/" . $view . ".php";
}
$this->view("path/to/my/views");
Thank you!
No, not possible as far as I can see. Closest discussion on PhpStorm tracker is https://youtrack.jetbrains.com/issue/WI-3468 but that wouldn't help much.
I have followed this setup, but not work for me http://www.cniska.net/yii-bootstrap/setup.html, all CSS files do not give style to the page,
So searching I found this thread How to install bootstrap extension in yii using some tricks. But not work's too.
Now I have this error
'Property "CWebApplication.bootstrap" is not defined.'
Anyone can help or have any idea?
Thanks in advance and for my English.
Property "CWebApplication.bootstrap" is not defined.
The error means the system is trying to access Yii::app()->bootstrap, which could be a property on the application. Since bootstrap is a component it should be accessible, if the configuration is done properly.
This error is most likely because you forgot the following in the main config file:
'components'=>array(
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
),
// This should point to the location you placed the files in for example extensions/bootstrap/components/bootstrap.php
The class location above will only work if the alias is set properly before setting the configuration.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
Instead you could also change "bootstrap.components.Bootstrap" into "application.extensions.bootstrap.components.bootstrap".
I strongly advise you to use Yiistrap, it was made by the person who create yii boostrap and the person who created Yiibooster. Yiistrap has everything from both extensions and more new stuff. here is the page http://www.getyiistrap.com , also has a fully documented API which yii boostrap do not have and it will save a lot of google searches.
Is it possible to use a custom view file in a module (eg. user) in order to keep the module (3rd party) intact?
Somehow extend the module, with a views folder that holds my custom views.
The path to the module theme views should be
/{{your_app_name}}/themes/{{theme_name}}/views/user/
Copy all of the module views from the folder
/{{your_app_name}}/protected/modules/user/views
to the mentioned above folder and that will do the job. After that you could customize the views as you like.
Copy user module view files to <app>/themes/<current_theme>/views/user/. More general, customize module views using the folowing "formula": <app>/themes/<current_tehem>/views/<modules_name>/<controller_name>/<view_file_to_customize>.php
Use a theme. For a module named "user" and a view path of "profile/edit", create "/themes/flashy/user/views/profile/edit.php". You can also define a new layout in "/themes/flashy/layouts/column2.php". Then add to your configuration file in "protected/config":
return array(
// many settings...
'theme' => 'flashy',
For the module "user" you pointed out, unfortunately its controllers use absolute paths for their layouts (e.g. "//layouts/columns2") so AFAIK you can't define distinct layouts for the application and this module.
See also the official guide chapter on theming with Yii.
I disagree that in many help forums of the Internet, when someone asks abot theming a module, everyone suggests a path alias to the themes folder. I think this is wrong, because it implies modules to be splitted, and modules are supposed to be a black-box that can be used across projects. The advice given in such forums would only be valid if a theme is shared among several modules. If someone wants to "package" a theme inside a module, she can:
-add an init function to the controller of the module
-inside that init, use the class attribute layout and a path alias, like this, supose a module whose id is "Sample":
then you add, to SampleCOntroller.php:
public function init() {
//BELOW: it will use the layouts/main.php inside the module.
$this->layouts = "sample.views.layouts.main";
}
I have just used Gii to generate a new module called gig. After generating the module code with Gii, I updated the config/main.php file to include the 'gig' module as follows:
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'secretpassword',
),
'gig',
),
Now, when I try to access the auto-generated Yii module code in my browser as follows:
http://localhost/gig/default/index/
I receive the following error:
DefaultController cannot find the requested view "index".
To fix this problem, I changed the render code in the module's DefaultController.php from this:
$this->render('index');
to this:
$this->render('gig.views.default.index');
This change resolved the problem, but I am wondering if I have missed something or if Gii is generating buggy code for modules? Anybody experience this problem before? Is my solution correct?
Now that the controller can find the view, I reloaded the page, only to be shown this error message:
Trying to get property of non-object
Turns out that there is a problem with the following code in the index.php view file:
$this->breadcrumbs=array(
$this->module->id,
);
I am not sure why this is happening. I tried changing the above code to the following:
$this->breadcrumbs=array(
Yii::app()->controller->module->id,
);
but this still gives me the same error message, "Trying to get property of non-object".
Any idea what may be wrong? Am I missing something when setting up the module code? I am using Yii 1.1.7
Thanks!
Sorry, it was our own stupid mistake. One of our programmers added a __construct method to the Controller class and forgot to include the $module variable in that method as follows:
public function __construct($id='site')
{
parent::__construct($id);
//custom code here
}
After adding $module variable as shown below, everything works fine now.
public function __construct($id='site', $module = null)
{
parent::__construct($id, $module);
}
If you don't need the breadcrumbs, simply delete that code block. If you do want them, make sure your Controller.php (which extends CController.php) class has:
public $breadcrumbs=array();
Then it should work as expected.
I'm not sure why you were having URL/path problems, but check your URL manager in config/main.php to see if there might be a rule that is causing problems. Seems to work for me without any rules, but if you do have some, try putting this first in the rules array:
'gig'=>'gig',
'gig/<controller:\w+>'=>'gig/<controller>',
'gig/<controller:\w+>/<action:\w+>'=>'gig/<controller>/<action>