Loading configuration items from another config file in CI - php

I've been trying to load a configuration item into another configuration file for my CodeIgniter app.
The reason for doing this is that I don't want to go through all of the files to change same parameters when I, for example, change the server or want to change the site title.
I've tried to get the items I need from the main config.php file by using $this->config['site_title'], by loading the config file using $this->config->load('config') and by loading individual config item using $this->config->item('site_title') but all of these methods return errors that the configuration items could not be loaded.
Am I missing something?

you should load the config files from the CI instance within a Controller
$ci = & get_instance();
$item_name = $ci->config->item('item_name');

simply create your config file in your ci config folder
myconfig.php
in it
$config['my_site_title'] = 'TechNew.In - www.technew.in';
and load your config in the controller
$this->load->config('myconfig');
then get your value
$my_site_title = $this->config->item('my_site_title');

Related

HMVC Integration in Codeigniter view paths

I am trying to intregrate HMVC to codeigniter. I have installed the MX files to thrid_party and uploaded the MY_Loader , MY_Loader and MY_Model to the application/core folder. it is working fine
I have two issues
1) How to add the module routes that overide the application routes
I am accessing module through the link localhost/domain/admin/portfolio
I have tried adding routes.php to the modules config application/modules/portfolio/config/routes.php with below details
$route['admin/portfolio'] = 'portfolio/admin/portfolio';
$route['admin/portfolio/add'] = 'portfolio/admin/portfolio/edit';
$route['admin/portfolio/edit/(:num)'] = 'portfolio/admin/portfolio/edit/$1';
On my root application config already added a routes
$route['admin'] = 'admin/login';
Because of this route 'admin/login' in the application/config/routes.php it is showing page not found. To fix this I have currently added the module/portfolio/config/routes`` above the 'admin/login'. Is there any other method instead of adding it to theapplication/config/routes`.
2) How to access the module view files
I have controller accessing the view files from application/controlles/admin/
$this->load->view('admin/view_header',$data);
$this->load->view('admin/view_portfolio',$data);
$this->load->view('admin/view_footer');
You have placed your Portfolio Controller under
application/modules/portfolio/controllers/admin
which is fine.
Your route (which will hit the index by default) should be
$route['admin/portfolio'] = 'portfolio/admin/portfolio';
Aside: other naming considerations
What I tend to do is to create a controller with admin in the name...
So I would have PortfolioAdmin.php or something along those lines, so I know by the file name, it's admin "Stuff", when I am playing with it in my Editor/IDE.
UPDATE:
In regards to your
Nor this works Modules::run('admin/portfolio', $data);
So you would then use the full controller name... Do not use routes, they are for URLs. Any module you want to call from another module you always use the full name.
Modules::run('portfolio/admin/portfolio', $data);

How to get a migration config item in CodeIgniter?

As usual, to access CodeIgniter's configuration item from a $config array, I would use this function $this->config->item('some_item');. That's fine, but how can I access a config items from this file app/config/migration.php ? where $config['migration_enabled'] is located
I'm doing a $this->config->item('migration_enabled') or $this->config->item('migration_version'), but it returns me always FALSE, anyone know why ? And how can I work it out to make it accessible within the controller ?
You need to load the migration config before you access it. You can either load it on demand in your controller via:
$this->config->load('migration');
or you can autoload it in your config/autoload.php file by adding it to the $autoload['config'] array:
$autoload['config'] = array('migration');

How to load view from alternative directory in Laravel 4

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).

Get to parent folder in codeigniter

I'm putting an DOMpdf creator in my Codeigniter application, but now i need to get an require_once to the parent folder. Somehow Codeigniter doesn't allow me to do this the "normal" way.
This is my require_once
require_once("../dompdf_config.inc.php");
How can I make this work in Codeigniter?
Try something like:
//APPPATH gives you path till application/ folder
require_once(APPPATH.'your_DOMpdf_file_path');
Hope it helps
To load a config file in CodeIgniter, you can call the $this->config->load() method.
To load one of your custom config files you will use the following
function within the controller that needs it:
$this->config->load('filename');
Where filename is the name of your config file, without the .php file
extension.
If you need to load multiple config files normally they will be merged
into one master config array. Name collisions can occur, however, if
you have identically named array indexes in different config files. To
avoid collisions you can set the second parameter to TRUE and each
config file will be stored in an array index corresponding to the name
of the config file. Example:
// Stored in an array with this prototype: $this->config['blog_settings'] = $config
$this->config->load('blog_settings', TRUE);
Please see the section entitled Fetching Config Items below to learn
how to retrieve config items set this way.
The third parameter allows you to suppress errors in the event that a
config file does not exist:
$this->config->load('blog_settings', FALSE, TRUE);
http://codeigniter.com/user_guide/libraries/config.html

Zend Framework - shared view script path ( global partials )

How is it possible to set up a shared view script path for partials to create global partials within the Zend Framework?
We know that you can call partials between modules
e.g - echo $this->partial('partial_title','module_name');
but we need to set up a partial folder in the root ( i.e below modules) so that it can be accessble by all views.
It has been suggested to set up a shared view script path, how is this done?
Zend_View has a method called addScriptPath, so in a Zend_Controller_Action subclass you could do something like:
$this->view->addScriptPath("/path/to/your/view/scripts/");
Now when you call render or partial or partialLoop, that path will be included in the paths.
I have got a solution. We can do this by specifying the location of the view:
Calling partial as above form Module/Controller page
Method 1:
$this->view->addScriptPath("/ModuleConatinerDirectory/ModuleName/view/scripts/");
Then load using:
$message = $this->view->partial('templates/default.phtml','contact',array('var'=> 'var');
For the second option, please read the following:
http://framework.zend.com/issues/browse/ZF-6201
Now my doubt is, whether it is possible on setting it directly on Bootstrap file for all my Modules ? If so, how can I set this for two modules Module1 and Module2
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' );
$viewRenderer->setViewBasePathSpec( '/some/absolute/path/to/templates/:module/' );

Categories