I'm new in laravel. However, I'm created blade templates and integrate with my offline index webpage. It consists of signin.html and signout.html. So below is the structure way of managing my files:
-views
--account
---signin.blade.php
---signup.blade.php
--includes
---head.blade.php
---footer.blade.php
--layouts
---master.blade.php
--home.blade.php
Home.blade.php
#extends('layouts.master');
Master.blade.php
<!DOCTYPE html>
<html>
<head>
#include('includes.head');
</head>
<body class="bg-info">
<!-- #include('includes.navigation'); -->
<!-- #extends('account.signin'); -->
<!-- #yield('content') -->
<!-- #yield('content') -->
#include('includes.footer');
</body>
</html>
The following two files will output the signin form in the page. I have no idea how they get into it. I didn't include anything. My public folder :
--assets
---css
---fonts
---images
---js
--index.php
--.htacess
Index.php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
$app->run();
$app->shutdown();
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Route
Route::get('/', array (
'as' => 'home',
'uses' => 'HomeController#home'
));
Home Controller
public function home() {
return View::make('home');
}
Now if I'm open-up my localhost, View [includes.master] not found. Perhaps my storage folder still contains the template codes, but I tried to delete, it keep generate a new one.
Another problem is when I adding #extends('includes.master') into signin.blade.php or singup.blade.php at the top.
The localhost and localhost/account/signin or localhost/account/register will be Internal Server Error: 500 .
Well, Let me tell you something. What's the need to include your header from an external folder? Please follow this, your master layout should be like this:
<!DOCTYPE html>
<html>
<head>
//put your codes here , not the include function
</head>
<body class="bg-info">
#include('includes.navigation');
#extends('account.signin');
#yield('content')
#include('includes.footer');
</body>
</html>
home.blade.php should be like this:
#extends(layouts.master)
#section('content')
<p> Hello, this works </p>
#stop
Now let me if you need any further help.
Check views folder permissions. In my case there was a problem.
For this folder and all the files inside permissions should be 755.
Had the same issue, think that has something to do with blades caching of the view dir. I fixed it by changing the #extends(example.master) to another template and then back to wanted path. Worked without doing anything else, but as always first try php artisan view:clear.
Greets, Pat
Related
new at codeigniter, trying simple code to load bootstrap css files with base_url() function.tried some answers on stackoverflow,but issue not solved.
my view name is.... articles_list.php
my controller name... user.php
i edit config.php as follow 'localhost/ci';
i edit autoload.php as follow i load url helper in autoload.php
articles_list.php (loading css in view file)
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.css') ?>" >
user.php(controller)
$this->load->helper('url');
$this->load->view('public/articles_list');
when i run my view file, css is not loading, when i check view source it should give me both stylesheet url and link address as "localhost/ci/assets/css/bootstrap.css" but when i see view source it show <link href="localhost/ci/assets/css/bootstrap.css"> and when mouse over at link it shows me localhost/ci/localhost/ci/assets/css/bootstrap.css link address. please
help me to solve this issue and help me to learn codeigniter.
Make sure you set the base_url right in application/config/config.php file:
$config['base_url'] = 'http://localhost/ci/';
And of course make sure to use the correct .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have create a controller in codeigniter. The problem is that when I hit the controller name and function name in url then Its give me error that 404 not found. I am new to codeigniter and I did not understand where I am going wrong
Here is my controller
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
function __construct(){
parent::__construct();
}
function you(){
$this->load->view('home_view');
}
}
?>
and my view is like this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First CodeIgniter Practice</title>
</head>
<body>
<h1> HELLO CI Buddy...!</h1>
</body>
</html>
I am creating my first project on codeigniter and I stuck in this problem.I already try most of the solution from the stackoverflow and after that I asking this question. So Its my request not to add this question to duplicate. I want solution for my problem. any help is appreciable
Thanks
I think there might be problem with .htaccess file. Do you have .htaccess file in your main project directory and is that written like following ?? If not make that so..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
Your issue may be due to any of the following reason
First letter of your controller file name should be in capital letter ie Home.php .
Please check your home page file name
Use the URL localhost/w3crud/index.php/home/you
if the issue is in your url then edit your .htaccess file
While thinking about this problem I wonder this might happened to starters like me
Suppose we have the project in a folder named codeigniter. so when typing the url we type something like this localhost/codeigniter/ and it shows the welcome message.But it automatically adds index.php defined in config.php (line 38) after the url like this localhost/codeigniter/index.php. So if you don't have mod_rewrite written in .htaccess file don't worry, try this url
localhost/codeigniter/index.php/home/you
in your case home.php is the controller file and you is the method here
Are you running your project on a live server? If yes, then make sure the filename of your controller starts with a upper case letter. It might seem like a silly answer but mind it that I myself spent more than five hours trying to fix the same problem.
Please try with following
a) Create member function index() in controller and check
b) Which url yor are checking?
b.1) http://localhost/yourproject/index.php/home/you
(localhot: is your server url, yourproject: your project folder, home = your controller file i.e. Home.php and you: your member function.
Try as following
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->load->view('home_view');
}
}
?>
and make sure your home_view.php file exist with your code in application/views directory. Now you may run URL http://localhost/w3crud/home/index to see the desired output
There are a lot of possible causes as to why it is happening. In my case, the cause is about the use of underscores in naming a controller e.g. My_Custom_Controller
routes.php (problematic)
$route['translate_uri_dashes'] = FALSE;
$route['my-custom-path'] = 'my_Custom_Controller/landing';
So, I was able to fix it by renaming the controller into Mycustomcontroller then that was the only time it worked.
routes.php (functional)
$route['translate_uri_dashes'] = FALSE;
$route['my-custom-path'] = 'mycustomcontroller/landing';
The naming doesn't follow the suggested naming convention of CodeIgniter but it definitely solved the issue for me.
If you have your CI in a subfolder, let say c:/xampp/htdocs/somemap/ci
Change your .htaccess to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /ci/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ci/index.php [L]
</IfModule>
Please note the /ci/
I want to change my address bar via htaccess.
My link is: http://englishforyou.ir/index.php?content=about
And I want to change it to http://englishforyou.ir/content/about.My htaccess code is:
RewriteEngine on <br>
RewriteRule ^content/([A-Za-z0-9-]+)/?$ index.php?content=$1 [NC]
But it doesn't work. You can test it here: englishforyou.ir
My index file is:
<?php
require_once 'includes/function.php';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div>
test
About me
</div>
<?php loadContent('content', 'mainpage'); ?>
</body>
</html>
My function file is:
function loadContent($where, $default='') {
// Get the content from the url
// Sanitize it for security reasons
$content = filter_input(INPUT_GET, $where, FILTER_SANITIZE_STRING);
$default = filter_var($default, FILTER_SANITIZE_STRING);
// If there wasn't anything on the url, then use the default
$content = (empty($content)) ? $default : $content;
// If you found have content, then get it and pass it back
if ($content) {
// sanitize the data to prevent hacking.
$html = include $content.'.php';
return $html;
}
}
And my about me file is:
<div>
<h4>
This page is about me.
home
</h4>
</div>
Your .htaccess file is right and it is working.
You might have to refresh your browser without cache, or wait for it to refresh by itself.
If you are using Firefox or Chrome, use Ctrl+F5 to refresh overriding the cache.
Note: You just have to use the url http://englishforyou.ir/content/about instead of http://englishforyou.ir/index.php?content=about
EDIT
Add this line to your .htaccess to redirect from http://englishforyou.ir/index.php?content=about to http://englishforyou.ir/content/about
RewriteRule ^index\.php\?content\=(.*)$ /content/$1 [R=301,L]
Try something like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^system/([^/]*)\.html$ system.php?route=$1
This translates the url http://www.domain.com/system/home.html to http://www.domain.com/system.php?route=home
And make sure you are allowed to use .htaccess
I have some trouble with my cms. (My own cms)
If I write www.example.com/example It works fine but if I write www.example.com/example/ the /example's content dosent show. Only the header, navigationbare, sidebar and footer shows up.
I need to write php code in site_content (In the mysql table) currently I can only write html)
It seems that google's spiders cant find my pages. Any way I can create a sitemap for google (The sitemap needs to get updated automaticaly when I add a new page in the mysql table (sites)
Structure of mysql
DataBase: website
Table: Sites
site_id
site_link
site_title
site_content
My index.php
<html>
<?php
include_once 'includes/mysqlconnect.php';
$url=$_SERVER['REQUEST_URI'];
$query = mysql_query("SELECT * FROM sites WHERE site_link = '$url' OR site_link = '$url/'");
WHILE($rows = mysql_fetch_array($query)):
$site_id = $rows['site_id'];
$site_link = $rows['site_link'];
$site_title = $rows['site_title'];
$site_template = $rows['site_template'];
$site_content = $rows['site_content'];
endwhile;
?>
<head>
<meta charset="UTF-8">
<title>KasCraft | <?php echo $site_title;?></title>
<LINK rel="stylesheet" type="text/css" href="http://kascraft.com/themes/default.css">
</head>
<body class="body">
<div class="container-all">
<div><?php include_once 'includes/header.php';?>
</div>
<div class="container">
<div><?php include_once 'includes/navigationbar.php';?></div>
<div><?php include_once 'includes/rightsidebar.php';?></div>
<div class="content">
<?php echo $site_content;?>
</div>
<div>
<?php include_once 'includes/footer.php'; ?>
</div>
</div>
</div>
</body>
</html>
And my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Can anybody please help me??
It could be that your .htaccess is only looking at the root directory of the site. /example/ is a new directory. I use a similar script that does include subdirectories, maybe you can use this:
RewriteEngine On
#In case of these folder, halt and don't continue.
RewriteRule ^(images|javascripts|styles)($|/) - [L]
#In every other case (exept these extentions) open index.php.
RewriteRule !.(gif|htm|html|ico|jpg|jpeg|js|png|txt|xml)$ index.php
With 'write php code' I assume you mean saving php code to the database? That works in the same way as saving html code. However when you're loading it from the database again you can choose to display it as text or execute it as PHP code using eval(). Personally I'd look at including templates in PHP. Have a look at this: https://stackoverflow.com/a/19603372/3079918
How long ago did you submit your website? It can take a few weeks before Google picks it up. If you really need a sitemap, build a script that will load your pages from the database and build them into a .xml file. Have a look at http://www.google.com/webmasters/ on how to submit the sitemap to Google.
I am trying to apply css in the Zend Framework. My css file is in public/css/layout.css. First of all I added the following code lines in bootstrap.php:
protected function _initPlaceholders()
{
$this->bootstrap('View');
$view = $this->getResource('View');
$view->doctype('XHTML1_STRICT');
// Set the initial title and separator:
$view->headTitle('My Site')
->setSeparator(' :: ');
// Set the initial stylesheet:
$view->headLink()->prependStylesheet('../../css/layout.css');
}
Which simply specifies the title and stylesheet to be used. Then in layout.phtml I add the following code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
echo $this->headTitle();
echo $this->headScript();
// add a link to the site style sheet
echo '';
echo $this->headLink();
?>
</head>
Which simply adds link of the stylesheet specified in bootstrap.php.
But when I run the project then I am getting the form without css. Why is this? When I check the css with Firebug in a Mozilla browser it says:
<h3>Exception information:</h3>
<p>
<b>Message:</b> Invalid controller specified (css) </p>
<h3>Stack trace:</h3>
<h3>Request Parameters:</h3>
<pre>array (
'controller' => 'css',
'action' => 'layout.css',
'module' => 'default',
) </pre>
Please help me out to resolve this issue.
Try
$view->headLink()->prependStylesheet('/css/layout.css');
this should help.
Do you have this code on your /public/.htaccess file?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
If you don't have the first 4 lines, this file will redirect your request of "css/layout.css" to index.php and then, Zend will interpret it as a link for a controller -> action.
If you have this file, make sure that mod_rewrite is enabled on your server.
And you sould put your link as "akond" said.
Good luck =)
This helped me:
Zend_Controller tries to execute my stylesheets as controller
[update]
Ok, just added the following line to my .htaccess file and all works as expected now...
RewriteRule !.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$ index.php
but then I found this one:
http://devzone.zend.com/1651/managing-css-and-javascript-files-within-a-zend-framework-app/