I have a problem with Codeigniter URL. I have a controller "welcome.php" :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$data['tiung'] = 'index';
$this->load->view('welcome_message',$data);
}
public function dor($bus)
{
$data['tiung'] = $bus;
$this->load->view('welcome_message',$data);
}
}
and a view "welcome_message.php" :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
</head>
<body>
sesuatu <?php echo $tiung?>
<img src="fragor.jpg" width="720" height="246" alt=""/>
ladalah
</body>
</html>
If I want to access the controller function 'dor' with a parameter I used this :
localhost/hostname/index.php/welcome/dor/something
and it works, but the problem is the image isn't loaded. I tried to put the image file in the webroot folder, 'application' folder, and even in the 'views' folder. But the image still can't load. Where should I put the image file?
The best practice for this is to create an /images/ directory in your webroot (the folder with index.php) and use the base_url() function to get the link to the image, I.E.
<img src="<?php echo base_url('images/fragor.jpg'); ?>" width="720" height="246" alt=""/>
Don't forget to load the url helper either with the autoloader or manually before using site_url() or base_url().
Also if you're using CodeIgniter's rewrite rules to remove the index.php from the URL (which it doesn't look like you're doing), don't forget to exclude the /images/ directory from the rewrite.
In CodeIgniter there is a specific way to indicate an image...like
echo img('images/gautam.gif');
put this in your view file and you need to create "images" folder at your root
Though you have to add CI helper 'html' in autoload config, but this goes easy after.
<?php
$image_properties = array(
'src' => 'images/picture.jpg',
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
'class' => 'post_images',
'width' => '200',
'height'=> '200',
'title' => 'That was quite a night',
'rel' => 'lightbox'
);
img($image_properties);
?>
/* <img src="site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a nigh`enter code here`t" rel="lightbox" />*/
OR JUST simple:
<?php
echo img('images/picture.jpg'); ?>
// gives <img src="site.com/images/picture.jpg" />
Related
I am using KoolReport Laravel page to generate report.
Koolreport has DataTables class but when i use it i got the error :
Class 'DataTables' not found (View: C:\xampp\htdocs\invoice\resources\views\reports\report.blade.php)
My code :
<html>
<head>
<title>My Report</title>
</head>
<body>
<h1>It works</h1>
<?php
DataTables::create([
"dataSource"=>$this->dataStore("users"),
"options"=>array(
"paging"=>true
)
]);
?>
</body>
</html>
Please include Datatable declaration as below in your Controller file.
<?php
use \koolreport\datagrid\DataTables;
?>
Or as an alternative, you can directly specify full path in blade file.
\koolreport\datagrid\DataTables::create([
"dataSource"=>$this->dataStore("users"),
"options"=>array(
"paging"=>true
)
]);
Reference links :
KoolReport datatables
KoolReport Blade
Try to use '\'
#php
\DataTables::create([
"dataSource"=>$this->dataStore("users"),
"options"=>array(
"paging"=>true
)
]);
#endphp
This might look useless question, but I'm unable to understand the problem here.
The problems are:
1. When I load the page, first this loads:
And then, after uploading the file:
this page loads:
2. yield('content') is not working. Although #include is working fine.
3. I made master.blade.php, to load the first page of the website. Before it, I was working on the welcome page.But, then changed the work of welcome with the master blade, but when the page gets loaded, it doesn't show anything.
Routes:
Route::get('/',function() {
return view('welcome');
});
Route::group(['middleware' => ['web']], function(){
Route::get('upload',function(){
return view('pages.upload');
});
Route::post('/upload','UploadController#upload');
});
views/pages/upload:
#extends('welcome')
#section('content')
<h2>Upload Files Here</h2>
{!! Form::open(array('url' => '/upload','files'=>true))!!}
{!! Form::file('file') !!}
{!! Form::token() !!}
{!! Form::submit('Upload') !!}
{!! Form::close() !!}
#endsection
views/welcome:
<!DOCTYPE html>
<html lang="en">
<head>
#include('partials._head')
</head>
<body>
#include('partials._nav')
<div class="container">
#include('partials._messages')
#yield('content')
#include('partials._footer')
</div>
#include('partials._javascript')
UploadController/Controllers:
if($request->hasFile('file')){
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('app.fileDesinationPath').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file- >getRealPath()));
}
return redirect()->to('/upload');
When it's working fine when I used include, to include the upload page in welcome, but the result is like shown in the pictures.Also, When I tried to use the master blade, and exclude the use of the welcome page, by erasing the content of the welcome page, the blank page gets loaded.
What changes do I have to make to make use of master instead of the welcome page? Why are two pages getting loaded? also, why isn't yield('content') not working?
Also, the file which I'm uploading is not getting saved in the public/uploads folder.
Please can anyone help?
I don't want that users can access images from simply using a URL like http://laravel.dev/123.jpg. Therefore I store all images in the storage directory, instead of storing them in the public folder.
With a controller like this
public function show($id) {
$img = storage_path('my_images/123.jpg');
return response()->download($img, null, [], null);
}
the image is correctly displayed by Laravel 5, although it is stored outside from the public folder.
Great up to this point ... but I want to use Blade and surround the image with some more details. Therefore my controller looks like this
public function show($id) {
$picture = Picture::find($id);
$img = storage_path('my_images/123.jpg');
return view('pictures.show', array('picture' => $picture, 'img' => $img));
}
and the view like this
<!DOCTYPE html>
<html>
<head>
<title>Picture {{ $picture->id }}</title>
</head>
<body>
<h1>Picture {{ $picture->id }}</h1>
<ul>
<li>Name: {{ $picture->name }}</li>
<li>Description: {{ $picture->description }}</li>
</ul>
<img src="{{ $image }}">
</body>
</html>
which obviously does not work, because the location of the image is not publicly accessible (which ist the intention).
What do I have to use instead of <img src="{{ $image }}"> to make this work?
Make the src attribute to call the URL of your first controller, this will work for you.
In other words, let's say, you have a route called image.show with that code.
public function show($id) {
$img = storage_path('my_images/123.jpg');
return response()->download($img, null, [], null);
}
So in your blade:
<img src={{route("image.show",$img_object)}}">
Not sure on the best way to go around this and am looking for solutions. I have the requirement to create a blank page (that I will later add code to) with a specific theme as the design. I've created the custom theme at: /app/design/frontend/indigo/mytheme/ and need to know how to create a page lets call it /test.php that has the theme applied to it.
Code so far is this, but this only shows the default theme:
<?php
define('MAGENTO_ROOT', $_SERVER['DOCUMENT_ROOT']);
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');
//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();
//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
$footerBlock = $layout->getBlock('footer');
echo $headBlock->toHtml() . $headerBlock->toHtml();
?>
My content goes here
<?php
echo $footerBlock->toHtml();
?>
The solution is quite basic, you just need to set the store ID:
Mage::app()->setCurrentStore(STORE_ID);
So the final code looks like this:
<?php
define('MAGENTO_ROOT', $_SERVER['DOCUMENT_ROOT']);
define('STORE_ID', 15);
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Mage::app()->setCurrentStore(STORE_ID);
Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');
//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo $layout->getBlock('head')->toHtml() ?>
</head>
<body>
<?php echo $layout->getBlock('after_body_start')->toHtml() ?>
<?php echo $layout->getBlock('global_notices')->toHtml() ?>
<?php echo $layout->getBlock('header')->toHtml() ?>
<div class="content-wrapper">
<div class="container_12">
<?php echo $layout->getBlock('breadcrumbs')->toHtml() ?>
<div class="main-container col1-layout">
<div class="grid_12 col-main">
<?php echo $layout->getBlock('global_messages')->toHtml() ?>
<?php echo $layout->getBlock('content')->toHtml() ?>
My content goes here
</div>
<div class="clear"></div>
</div>
</div>
</div>
<?php echo $layout->getBlock('footer')->toHtml() ?>
</body>
</html>
I think there are cleaner solutions you could take out of these: https://magento.stackexchange.com/questions/154974/create-completely-empty-page-in-magento-1-9-2-4 depending on how close to core you want to be :)
EDIT - A Clean complete solution:
Create a new custom controller (https://www.pierrefay.com/magento-training/create-a-controller-tutorial.html)
class Vendor_Module_LoremController extends Mage_Core_Controller_Front_Action
{
/**
* Get a shop now block for specific product
*/
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
// Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles()); // If you need to debug to see which layout handles are available
}
}
In your themes local.xml ( /app/design/frontend/[vendor]/[theme]/layout/local.xml ):
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<vendor_module_lorem_index>
<remove name="header" />
<remove name="footer" />
</vendor_module_lorem_index>
</layout>
i use of ajaxLink in my view code, the ajaxLink that is in action views work nice but when i put ajaxLink in layout it don`t work.
i saw the executed code and understood there isn`t javascript code for layout ajaxLink!!
i think there is a conflict !!
ajax link code :
<?php echo $this->ajaxLink("change password",
$this->url(array("module"=>"admin" , "controller" => "user" , "ajax" => "on" ,"action" => "changepass"), "" ,false , false),
array('update' => '#container',
'method' => 'GET',
'beforeSend' => 'showLoadingImage();',
'complete' => 'hideLoadingImage();')); ?>
this code creating automatically for every link but this code didn`t create for ajaxlink in layout! :
$('a.ajaxLink1').click(function() { showLoadingImage();$.get('/donyaye_fan_zend/public/admin/link/index/ajax/on', {}, function(data, textStatus) { $('#container').html(data); hideLoadingImage(); }, 'html');return false; });
what`s wrong?
In your layout file (layout.phtml) place line : <?php echo $this->jQuery(); ?> just before </body> tag, not between <head>...</head> tags.
The layout file should look like this:
<head>
...
</head>
<body>
<div id="some_div>
...
</div>
<?php echo $this->jQuery(); ?> // <-- add this line here not in <head> section
</body>