I downloaded the EasyImage extension for Yii to crop images but whenever i want to init the image this fatal error comes up:
Fatal error: Call to undefined method Image::factory() in C:\Users\Daniel\Documents\GitHub\askengine\protected\extensions\yii-easyimage\EasyImage.php on line 41
Cant figure out why.
My Controller:
Yii::import('ext.yii-easyimage.EasyImage');
$image = new EasyImage("avatar/".$fileName);
$image->crop($_POST['w'], $_POST['h'], $_POST['x1'], $_POST['y1']);
$image->save();
The EasyImage class _construct():
public function __construct($file = null, $driver = null)
{
if ($file) {
return $this->_image = Image::factory($this->detectPath($file), $driver ? $driver : $this->driver);
}
}
And the Image.php :
public static function factory($file, $driver = NULL)
{
if ($driver === NULL) {
// Use the default driver
$driver = Image::$default_driver;
}
// Set the class name
$class = 'Image_' . $driver;
return new $class($file);
}
I tried to use directly the Image.php but it ended with failure:
Fatal error: Call to undefined method Image::factory() in C:\Users\Daniel\Documents\GitHub\askengine\protected\controllers\ImageController.php on line 60
Related
I am using method post to create new data in xml file but The function c_element cannot be used in the function store
$DeTai = c_element('DeTai', $root);
This is my current code:
public function c_element($e_name, $parent)
{
global $xml;
$node = $xml->createElement($e_name);
$parent->appendChild($node);
return $node;
}
public function c_value($value, $parent)
{
global $xml;
$value = $xml->createTextNode($value);
$parent->appendChild($value);
return $value;
}
public function store(Request $request)
{
$xml = new DOMDocument("1.0","UTF-8");
$xml->load('../xml/QuanLyDoAnTotNghiep.xml');
if ($request->isMethod('post'))
{
$madt= $request->madt;
$noidungdetai = $request->noidungdetai;
$root=$xml->getElementsByTagName("QuanLyDoAnTotNghiep")->item(0);
$DeTai = c_element("DeTai", $root); //error in here
$s_madt = c_element('MaDT', $DeTai);
c_value("$madt", $s_madt);
$s_noidungdetai = c_element('NoiDungDeTai', $DeTai);
c_value("$noidungdetai", $s_noidungdetai);
$xml->formatOutput=true;
$xml->save('../xml/QuanLyDoAnTotNghiep.xml');
echo "Thêm mới thành công!!!";
}
}
use this keyword to call one method in different method of same class
$DeTai = $this->c_element('DeTai', $root);
to know more about it please visit this
Thanks..
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method MY_Loader::_ci_object_to_array()
Filename: C:\xampp\htdocs\hhh\application\third_party\MX\Loader.php
Line Number: 300
Try this. Add it in the MY_Loader.
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* load the MX_Loader class */
require APPPATH."third_party/MX/Loader.php";
class MY_Loader extends MX_Loader
{
/** Load a module view **/
public function view($view, $vars = array(), $return = FALSE)
{
list($path, $_view) = Modules::find($view, $this->_module, 'views/');
if ($path != FALSE)
{
$this->_ci_view_paths = array($path => TRUE) + $this->_ci_view_paths;
$view = $_view;
}
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => ((method_exists($this,'_ci_object_to_array')) ? $this->_ci_object_to_array($vars) : $this->_ci_prepare_view_vars($vars)), '_ci_return' => $return));
}
}
SOLVED
I get this error when I got to a page where I call a method in template.
ErrorException in Product.php line 104:
Trying to get property of non-object (View: C:\wamp64\www\ibpc\resources\views\admin\products\edit.blade.php)
In blade template I am calling a method attribute:
{{ $product->attribute($attribute->id) }}
$product in template is passed from controller as:
$product = Product::with('categories.specifications.attributes')->find($id);
Method attribute in Product.php:
public function attribute($id)
{
$attribute = $this->attributes()->find($id);
$test = $attribute->pivot->value;
return $test;
}
I did debug with xdebug and everything seems to be fine:
Why the error?
If I do something like this then I get no errors:
public function attribute($id)
{
return 'Hello';
}
I had to check for empty values...
public function attribute($id)
{
$attribute = $this->attributes()->find($id);
if ($attribute) {
$test = $attribute->pivot->value;
} else {
$test = null;
}
return $test;
}
http://127.0.0.1/masterlinkci2/admin/cpages/pages
I get this error message:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Cpages::$gionda_date
Filename: controllers/Cpages.php
Line Number: 200
Line 200: $data['gionda_date'] = $this->gionda_date->g_date();
controllers/Cpages.php
public function pages() {
$data['pagessuccess'] = '';
$data['pages'] = $this->Mpages->call_pages();
$data['gionda_date'] = $this->gionda_date->g_date();
$this->load->view('pages', $data);
}
libraries/gionda_date.php
class Gionda_date {
private $CI;
public function __construct()
{
$this->CI = &get_instance();
}
public function g_date()
{
$datestring = 'Year: %Y Month: %m Day: %d - %h:%i %a';
return $datestring;
}
Can anyone help me fix the error messages?
Is you library loaded in your Cpages controller?
$this->gionda_date->g_date();
edited because of comment here is the most likely solution:
$this->load->library('gionda_date')
My code is
public function listCompanies()
{
$companyObj = new company();
$companies = $companyObj->getCompanies();
$this->layout->content = View::make('admin/main',['companies'=>$companies]);
}
The error I am getting is
ErrorException
Creating default object from empty value
The error line is
$this->layout->content = View::make('admin/main',['companies'=>$companies]);
Set a:
protected $layout = 'your_layout_name';