I have a plugin and inside the plugin I have a Lib folder.
Like this:
Lib/Billing/CMS/CMS.php
How can I use the CMS class inside CMS.php on my controller? Not my plugin controller, but a controller on my application.
EDIT: Cake version is 2.3
So, from your short information one can only guess...
Your plugin is "Billing"?
Your files are
APP/Plugin/Billing/Lib/CMS/CMS.php (class CMS)
APP/Plugin/Billing/Lib/Billing.php (class Billing)
You include classes always the same, using App::uses().
Then its
App::uses('CMS', 'Billing.CMS'); // Filename, Plugin.Package
and
App::uses('Billing', 'Billing.Lib'); // Lib as package namespace here due to lack of a proper one
I do not have to point out, that you need to load your plugin first, right?
Using CakePlugin::load()/loadAll()
Related
I have two versions of my project. For one i use a different CSS and index page and for another i use different. Rest of the things that is controller, models and components are same. The only difference is in view(one or two files) and CSS.
Is there any way to manage this? Like when the URL is URL1 then use CSS1/View1 folder and when url is URL# use CSS2/view2 folder. I have gone through the modules section of Yii but i don't think they are what i need here.
So now I started to use themes. My folder structure is like:
WebRoot
- assests
- css
- images
- protected
- themes
- theme1
-views
-site
-layout
-template
- theme1
-theme2
-views
-site
-layout
-template
In my controller I have done this:
public function init() {
if (SITE_TITLE == 'xxxxx')
Yii::app()->theme = 'theme1';
else
Yii::app()->theme = 'theme2';
parent::init();
}
Which sets theme correctly. but i keep getting file not found as renderer is looking in protected.
I think, you need use themes. Here is documentation: http://www.yiiframework.com/doc/guide/1.1/en/topics.theming
UPDATED after discussion
Trouble in ETwigViewRenderer and it working with themes
If you want to change entire layout, perhaps this is a good way to do:
Setting Layout in Yii
In case you want only to change css they why don't you rely on request uri or domain name?
Yii::app()->getBaseUrl(true)
In my Laravel 4 application's root directory, I have a folder themes. Inside the themes folder, I have default and azure.
How can I access view from this themes/default folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
My directory structure:
-app
--themes
---default
---azure
I need to load views from localhost/laravel/app/themes/default folder. Please explain this.
This is entirely possible with Laravel 4. What you're after is actually the view environment.
You can register namespace hints or just extra locations that the finder will cascade too. Take a look here
You'd add a location like so:
View::addLocation('/path/to/your/views');
It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.
View::addNamespace('theme', '/path/to/themes/views');
return View::make('theme::view.name');
You can also give addNamespace an array of view paths instead of a single path.
Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.
I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,
You'd add a location like,
View::addLocation('/path/to/your/views');
Then add namespace for theme,
View::addNamespace('theme', '/path/to/themes/views');
Then render it,
return View::make('theme::view.name');
What will be the value for /path/to/ ?
Can I use the same project in different operating system without changing the path?
Yes, we can do this using the following,
Put the following in app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
Then call view like the default way,
return View::make('page');
This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.
I've developed a theme package for laravel 5 with features like:
Views & Asset seperation in theme folders
Theme inheritence: Extend any theme and create Theme hierarcies
Try it here: igaster/laravel-theme
\View::addLocation($directory); works fine but the new right way to do it is using loadViewsFrom($path, $namespace) (available on any service provider).
1- How can I register and call my plugin in bootstrap file?
2- Is it a better way to use boostrap file intead of application.ini file for registering and calling my plugins ?
Note: Iam using custom path ('Mylib/Controller/Plugin') for storing my plugins.
Actually I want to convert following 'application.ini' entries
autoloaderNamespaces[] = "Mylib_"
resources.frontController.plugins.CheckHasAccess = "Mylib_Controller_Plugin_CheckHasAccess"
into bootstrap _initPlugin function.
Can some one guide me in this regards with some sample code.
Thanks in advance
1 - You would need first to load your plugin class (via Zend_Loader or require_once)
then create your plugin yourself:
$plugin = new MyPlugin();
then you can call any public method of your plugin you want and at the end you can register it within front controller:
Zend_Controller_Front::getInstance()->registerPlugin($plugin);
2 - if your plugins need to be somehow configured before they can be used by framework - then you can create and configure them yourself (as described above). If they don't need any special actions - then you can let them to be created by Framework automatically.
I am trying to load the Vzaar libraries into Codeigniter. Should these file go into the libraries directory. If so there are multiple files, which one would I make the call to from my controller. I believe the main library file is Vzaar.php. Therefore should my call be
$this->load->libraries('Vzaar');
Presumably this library is a standard PHP class called Vzaar? If so, then yes, what you've said is correct. Put Vzaar.php into your application/libraries folder and load it up at any time using $this->load->libraries('Vzaar'). Then you can use it by doing $this->Vzaar->myFunction(). For more info, check out CI's awesome user guide:
http://codeigniter.com/user_guide/general/creating_libraries.html
Yes, $this->load->libraries('Vzaar') followed by $this->Vzaar::function_name() should do the job, since it's just a PHP class and it has all require_once instructions inside of it already.
Evi Skitsanos,
vzaar API Head of Support,
email: evi#vzaar.com | twitter: http://twitter.com/skitsanos
I have two modules, default and mojo.
After the initial bootstraping code which is the same for both of the modules, I want, for example, to use different layouts for each module (Or use different credentials check etc).
Where do I put this: IF(module=='mojo') do this ELSE do that
If you are using Zend_Application (in ZF1.8) then you should be able to use the module specific configuration options to provide this functionality with a as explained in the relevant section in the documentation.
This would require you to set the layout in the config so it looked something like
mojo.resources.layout.layout = "mojo"
anothermodule.resources.layout.layout = "anotherlayout"
The layout would then be set automatically by the bootstrap.
The other alternative is to use a front controller plug-in that implements the preDispatch() method to set the layout based on the module name.
hmm i havent tried this
http://www.nabble.com/Quick-Guide-How-to-use-different-Layouts-for-each-module-to23443422.html#a24002073
the way i did that now was thru a front controller plugin
something like
switch ($request->getModuleName()) {
case "":
// set layout ...
}
I've looked into the subject a couple of days ago, trying to get it to work on bootstrap config alone. The big problem is that all the bootstrap files are loaded, so it gives some weird results in which layout is used.
My conclusion was that you can have the config in place, but you need to work with FrontController plugins or ActionController helpers. If you want to use config set in the application.ini and you want to load the config trough the bootstrap, helpers is the only way to go. From the helper, you can then load the ActionController and on that execute the getInvokeArgs to load the bootstrap. A lot of hastle... :)
Anyway, I've done a small implementation as an example in a blog post: http://blog.keppens.biz/2009/06/create-modular-application-with-zend.html
Goodluck,
Jeroen