How to load view from application/myfolder/ path in CodeIgniter - php

I was loading view in CodeIgniter as
$this->load->view('../../myfolder/footer');
It was working fine on windows machine. I have uploaded app to linux machine and start getting error
Unable to load the requested file: ../../myfolder/header.php
myfolder is in CI application folder.
How can i load view from application/myfolder
Please help me and thank you in advance.

Why you need tho load views in application/myfolder?? Code Igniter expects that views are located in application/views or application/views/myfolder. Put your files in application/views and then you can load it using:
this->load->view('footer');
or
this->load->view('myfolder/footer');

If it worked on Windows but no longer works on Unix, it could be because the filepaths are case sensitive in Unix.
Check the file structure and file names to make sure they match the CodeIgniter requests exactly.
E.g.:
$this->load->view('../../myfolder/footer');
Will fail trying to load:
../../MyFolder/footer
../../myfolder/Footer
../../MyFolder/Footer
etc

$this->load->view(base_url().'myfolder/footer');
That should work but I have no idea why you're trying to work outside the views folder to begin with. Just structure your views folder like below. Load the header, footer and anything else that's static from a template page.
Views
--pages
--admin
--templates
--etc.

Related

Apache not loading view inside another view of codeigniter

I wrote a codeigniter app and deployed in apache. after checking in browser, single view controllers are loading very fine. but i made all css headers and some session management codes into one php file named header.php. So i had to call this php view in every other views. But, browser shows
Unable to load the requested file: Header/header.php
i wrote this line in my all views to call header view
<?php $this->load->view('Header/header.php'); ?>.
Any help would be appreciated.
I finally found solution. When running CI app in localhost, it is not that case sensitive. actually i tested it in windows. Windows is not much case sensitive in directory names. But, when CI app deployed in apache ubuntu it becomes more case sensitive. Inside every module, CI models, controllers, views folder names should be in lowercase. In my case, views folder of Header module was Uppercase.

Laravel 4 treating files as routes in laravel 4

I am just trying to host a laravel site to production. There is an error with the routing all my css and javascript files are being treated like a route instead of files and they are not loading
<script src='http://project.com/project/assets/js/jquery-1.9.1.js' type='application/javascript'></script>
I can see that this html is generated but the files are not being loaded When I click on the link I get a NotFoundHttpException
This is wroking fine in my local machine. This error is present only in live server.
Thanks in advance!
The src link to your js file is set using Laravel's HTML::script()? If not change it because this will help so that you can have proper full urls for js and css files. So if you have a js file like public/assets/js/custom.js you should call it like this:
{{ HTML::script('assets/js/customs.js') }}
and you will be fine. Just remember that your starting point for assets is inside public folder. HTML::script() or HTML::style() get you there at once.
It turns out the issue is with nginx configuration. The root folder to the server was set incorrectly. So it was looking for differnt files. Not a code issue just and issue with the server environment

wordpress integration with codeigniter base functions conflict

I have developed the CRM based web application what i need to do is to integrate the wordpres with my CI first i have the problem when i include the main WP file
require('./wp-blog-header.php');
in my one of the CI view file the error i was getting that function site_url() conflicts this function is the base function of both WP and CI ,although i found a solution to include the WP file in the main index.php file of CI but there is uncertainity too that after this the session library of CI stops working is.
How to show the posts of WP in the footer of my CRM?
When using include or require in my CodeIgniter views I make sure the files I am linking to are outside of the CodeIgniter application folder as I had trouble using files there because of some permission problems. My solution was to just keep a folder in my web directory. You also cannot use base_url or site_url CodeIgniter functions here since you want to get the server path not the web address of the file. So you can use the php variable $_SERVER['DOCUMENT_ROOT'] which will return the root of your web directory.
It might look something like this:
require($_SERVER['DOCUMENT_ROOT'].'wp-blog-header.php');
Which would work if wp-blog-header.php was in your web root directory.

How do I get CakePHP configured so it shows up correctly in my browser?

I am a cakephp newbie and I had trouble to view the files under the view folder through browser.
I used cakephp console to bake model, controller and views. (ex: Invoices_controller.php for controller, invoice.php for model and a invoices folders under views folder). According to the tutorial I read, I can access the invoice view by typing http://localhost/myProject/invoices
(there is no index.php inside the invoices folder..but the tutorial shows it still can display a page. no idea how they did it)
The path for my invoices is myProject/views/invoices and there add.ctp, index.ctp, edit.ctp files inside the invoices folder.
The browser showed the file is not found when I typed http://localhost/myProject/invoices
You have some lack in your knowledge about how the webserver handling a request when cakephp is installed. Assume that we use apache.
In cake's folder structure you can see .htaccess files in the root, app and webroot directories what have url rewrite rules in them. At the end a normal request to a cakephp site will be transformed to a http://site.url.root/app/webroot/index.php?url=original.url
In nutshell to understand it in your point of view:
That index.php call the required php files and at least a cakephp app object is built up in the memory with the required models and methods. Then the app object let say start and calls its methods (model, controller and view methods) and at the end it gives back a result to apache what serves it to you.
Therefore the original url path is a "non existent" virtual url.
If you enter http://localhost/myProject/ do you get a cake intro page? If so does it highlight any problems?
It sounds to me as if you do not have Apache set up properly. I don't know what OS you're using, but it might be worth checking this link, written for Ubuntu, to make sure all is well: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html
I fixed the same problem.
if you are using windows 7 os, wamp server, cakephp 2.2.3. then
goto apache -> http.conf -> open -> search for mod_rewrite -> uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
Now restart your server, now it should work fine.
Jerry, I think the issue is this. You have put the CakePHP folder in the root of localhost. I would propose that you create a virtual host pointing the myProject so the url becomes:
http://myProject/accounting
This may solve your problem. Be sure rewrite module is on. Also, when you point the virtual host to myProject, it should be the APP folder of the cakephp. If you want to run multiple projects off the same core, you can set them up like so:
/var/www/cake
/var/www/html/myProject
/var/www/html/myProject2
The /var/www/cake directory is where you drop the cake core. Under this directory you will have cake, app, plugins, vendors, etc. the myProject(2) directories will be the contents of the app directory.
Now, to get this to work, you need to go to /var/www/html/myProject/webroot/index.php and edit it to point to the cake directory in /var/www/cake. This will then load the core when rewrite points to index.php in webroot. You should be good to go!

Missing Helper file error in cake php on shared hosting

I am getting a Missing Helper error when I am trying to upload my cake php files to a shared host.
Undefined variable: javascript
Missing Helper File
It is working fine on my local machine.
I have the following directory structure in shared hosting:(using cpanel)
/home/user/
/app
/cake
/vendors
/public _html
/css
/img
/js
.htaccess
index.php
I have also made all the relevant changes to the index.php file and I was getting the full colored cake php intro page.
The strange thing is that it is recognizing the HTML helper and hence i am able to see my web page with full CSS. However, it is giving problems with javascript and other helpers.
I already have an app_controller file with all helpers well defined in $helpers =array().
Why is it giving this error??
As mentioned above, I have made changes to my cake directory structure. So, do I have to make changes to the paths.php file located in the cake/config folder??
I think that cake is not finding the javascript helper because something is messed up with config files. Is it so or there is some other problem??
in /app/app_controller.php, add:
var $helpers = array('Javascript');
your structure doesn't seem like cakephp structure :-(
Guys, I found a simple way to tackle this problem. I certainly cannot call it the solution for the problem. May be a temporary way to make things work.
I simply replaced
<?php echo $javascript->link(array('tabulator')); ?>
with the standard HTML,
<script type="text/javascript" src="/blog/js/tabulator.js"></script>
and it worked!!
I still don't know the problem with javascript helper. All other helpers, Html, Form and Ajax are working fine. I am also using Gravatar for my blog. So, the Gravatar Helper was also giving problems.
The solution to this problem was weird.
I renamed the helper file gravatar.php instead of Gravatar.php. This worked insipte of the fact that helper file name should begin with a capital letter according to cake naming conventions!!
I also had to solve numerous other problems like making changes to the index.php file so that cake can locate the modified directory structure.
Also, had to make changes to .htaccess file for rewriting the base and directing the blog to the new URL.
Man..so much for rapid development!! :O

Categories