CodeIgniter template library problems - php

I am trying to use a template library with my current codeigniter project. However I am getting the following error message,
Unable to load the requested file: main.php
My file system looks like this,
/application
/themes
/views
/layouts
admin.php
In MY_Controller.php I have the following,
<?php
class Dashboard extends MY_Controller {
public function __construct()
{
parent::__construct();
}
}
?>
In my controller I have the following
<?php
class Dashboard extends MY_Controller {
public function __construct()
{
parent::__construct();
//$this->template->set_layout('admin');
}
public function index()
{
$this->template
->set_layout('admin') // application/views/layouts/two_col.php
->build('welcome_message'); // views/welcome_message
}
}

It depends what template system your using, from the sounds of it you're using Phil Sturgeon's template library.
If so open up config/template.php
and find this line:
$config['layout'] = 'main';
And edit it as applicable.

Which template system are you using? I guess it needs a file named main.php which will load the view. Or the file does not exist and you will have to add it or the path to the file is not correct

Related

Codeigniter cannot load helpers

I have checked all config files, made sure the helpers are in both system/helpers and application/helpers as well as one or the other. I have tried autoloading helpers, loading the helper in my controller and from the view and no matter what I get an error.
Unable to load the requested file: helpers/_helper.php
It is treating it as if I am trying to load a blank helper such as $this->load->helper(''); but I am using $this->load->helper('url');
This is my controller to load my home page
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
}
public function index(){
$this->load->view('templates/header');
$this->load->view('home');
$this->load->view('templates/footer');
}
}
system/helpers/url_helper.php and application/helpers/url_helper.php both currently exist and have not been edited at all.
If needed I can include my autoload.php but the helper Auto-load Helper Files is currently $autoload['helper'] = array();
If you need to over ride the url helper
rename the file
application/helpers/MY_URL_helper.php
OR
application/helpers/MY_url_helper.php
Copy the whole path inside the url, like this , (wamp)
$this->load->helper('www/projectfoldername/applications/libraries/helpers/helperfile');

Css not load in Codeigniter framework

I have this code file in Codeigniter, but the URL method doesn't work also try so really I don't see problem here.
<?= link_tag('asstes/css/bootstrap.min.css') ?>
load through helper $this->load->helper('html');
What am I doing wrong?
On CodeIgniter 3 versions Just check if your base_url is set because some times having that blank can cause links not to work properly.
$config['base_url'] = 'http://localhost/your-project/';
Controller example: Welcome.php
<?php
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('html');
}
public function index() {
$this->load->view('welcome_message');
}
}
Or auto load html helper
$autoload['helper'] = array('url', 'html');
In your head tag on view link_tag guide
<html>
<head>
<?php echo link_tag('assets/css/bootstrap.css');?>
</head>
Folder Example
application
assets
system
index.php
You have an error in your string path
asstes ---> assets
I think it's better to write your own helper for add your resources (js, css...)

How do you create a custom page in Presta Shop?

I have followed many tutorials, but they are either cryptic or they did not work, or they wanted you to use the terrible CMS block module which gives you limited control over the custom elements of a page.
So far:
I created a controller called ProgramsController.php and put it into ps_root/controllers/front
class ProgramsControllerCore extends FrontController
{
public $php_self = 'programs';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'programs.tpl');
}
}
I created a template called programs.tpl and put it into ps_root/themes/mytheme/ folder
I then use: localhost/index.php?controller=programs or I use the SEO and links builder to create a localhost/programs link, and I get an error: Fatal error: Class 'ProgramsController' not found in ...\classes\controller\Controller.php on line 135
But that's not right since the path ought to be a ../controllers/front path, why is it looking in ../classes/controller? I assume from all the tutorials that the dispatcher should know to hook my front controller to the correct template. Why is this not working?
Basic Question:
In PrestaShop 1.6 I just want to know how to create custom pages like: http://myshop.com/mycustompage
But that it also utilizes the existing header and footer.
For creating a new custom page you have to follow some steps:
you have to create a new folder in your modules folder of prestashop like
C:\wamp\www\prestashop\modules\your_module_name
Then you put your controller file in your module folder like:
C:\wamp\www\prestashop\modules\your_module_name\controller\front\your_file.php
And in that you code like:
class ProgramsControllerCore extends FrontController
{
public $php_self = 'programs';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'programs.tpl');
}
}
Then you make a new folder views in your module like:
C:\wamp\www\prestashop\modules\your_module_name\views
Then in that you make another folder named template and in that another a folder named front like:
C:\wamp\www\prestashop\modules\your_module_name\views\templates
C:\wamp\www\prestashop\modules\your_module_name\views\templates\front
Then in that file you have to put your theme file Like
C:\wamp\www\prestashop\modules\your_module_name\views\templates\front\programs.tpl
and now render your file. I hope it would work.

Codeigniter modular extensions HMVC won't load view

I am using the modular extensions HMVC add on for codeigniter.
my structure looks as follows:
modules/
-manager/
--controllers/
---manager.php
--views/
---index.php
the manager.php controller:
class Manager extends MX_Controller {
function __construct(){
parent::__construct();
}
function index(){
$data['newsletter'] = Newsletter::all();
$this->load->view('index',$data);
}
}
Routing and printing from inside the controller itself works fine, but I can't seem to load a view, get a codeigniter error saying the view file can't be found
/modules/manager/config/routes.php:
<?php
$route['module_name'] = 'manager';
It seems the views are still being called from CI's main view folder, not sure why they are not calling from the modules folder because the controller is extending the MX class
Try this:
$this->load->view('manager/index',$data);
Structure for folders:
apllication
modules
manager
config
routes.php
controllers
manager.php
views
index.php

Class Not Found when extends a Class of Subdirectory Controller in ZendFramework

I've the next structure
-application
--controllers
---Sub
----DemoController.php
---IndexController.php
-models
-views
-Boostrap.php
Well, in my Sub/DemoController.php I've the next:
<?php
class Sub_DemoController extends Zend_Controller_Action
{
public function indexAction()
{
echo 'hello demo';
}
}
And my IndexController.php like this:
<?php
class IndexController extends Sub_DemoController
{
}
When I run my web throw the next error: Class 'Sub_DemoController' not found ...
I try with initialize class with Application_Sub_DemoController, but return the same result.
I don't want use modules, I know how uses modules in Zend Framewoork but I don't looking for it.
Any ideas?
You need to add resourceType to your resource autoloader add this to you bootstrap file:
$this->getResourceLoader()
->addResourceType('sub', 'controllers/Sub', 'Sub');
More: http://framework.zend.com/manual/1.12/en/zend.loader.autoloader-resource.html
Please have a look at Zend framework (1.7.5): how to change controller directory
I think you didn't set the controller directory properly or your autoloader does not work.

Categories