I recently update lithium library and I have this problem.
I get this error:
RuntimeException
Deprecated `app\models\StoreCategories::__init()` method, needs to be called it manually.
Source
/works/minhna/public_html/CMP/V0/libraries/lithium/core/Libraries.php: 505
500
501 if ($path && include $path) {
502 static::$_cachedPaths[$class] = $path;
503 if (method_exists($class, '__init')) {
504 $msg = "Deprecated `{$class}::__init()` method, needs to be called it manually.";
505 throw new RuntimeException($msg);
506 }
507 } elseif ($require) {
508 throw new RuntimeException("Failed to load class `{$class}` from path `{$path}`.");
509 }
510 }
In the StoreCategories model, I have a simple function
public static function __init(array $options = array()){
static::config($options);
static::applyFilter('save', function ($self, $params, $chain) {
if(!$params['entity']->_id){
//set created date
$params['entity']->created = strtotime(gmdate('Y-m-d H:i:s'));
}
}
}
I use composer and in the boostrap libraries.php, I load the li3_socialauth library:
/**
* load the socialauth library
*/
Libraries::add('li3_socialauth');
// Add the composer autoloader if not already done
require_once(LITHIUM_LIBRARY_PATH . '/autoload.php') ;
Thank you in advance.
Lithium got rid of __init() in static objects, see this commit.
Related
Confession:
I read many similar questions on this platform, but nothing seems closely aligned to my situation. Most of the questions seem to originate from binding params in prepared statements or execute statement.
In my case, the website runs smooth on a local server(Apache2). However, it throws the error below when published on live server.
Fatal error: Uncaught Error: Call to a member function signin() on boolean in /storage/ssd5/815/17670815/app/controllers/signin.php:16 Stack trace: #0 /storage/ssd5/815/17670815/app/core/app.php(33): Signin->index() #1 /storage/ssd5/815/17670815/public_html/index.php(4): App->__construct() #2 {main} thrown in /storage/ssd5/815/17670815/app/controllers/signin.php on line 16
Context
I'm using MVC (OOP) in PHP and here the relevant parts mentioned in the error. I hope this is not too much.
In the main index page, the line referred in the error is a core class(App) instantiation
<?php
session_start();
require_once '../app/initializer.php';
$app = new App(); //this is the line 4 mentioned in the error
In Signin controller class the line referred in the error is indicated below
<?php
class Signin extends Controller{
function index(){
//you can do this if passing data to view
$data["Page_title"] = "Signin";
if($_SERVER['REQUEST_METHOD'] == "POST"){
// this is a debuggin code
//echo "I am signin controller <br />";
// show($_POST);
$user = $this->loadModel("User");
$user->signin($_POST); //this the line referred in the error
}
$this->view("zac/signin",$data);
}
}
In class APP the line is a callback - check below
<?php
class App {
private $controller = "home";
private $method = "index";
private $params = [];
public function __construct()
{
$url = $this->splitURL();
if(file_exists("../app/controllers/".strtolower($url[0]).".php")){
$this->controller = strtolower($url[0]);
//unset the array position
unset($url[0]);
}
require "../app/controllers/".$this->controller.".php";
// echo file_get_contents('http://smart-ecom.000webhostapp.com/app/controllers/'.$this->controller.".php");
//Create instance of whatever controller class is passed(if it exists, otherwise the home controller)
$this->controller = new $this->controller;
if(isset($url[1])){
if(method_exists($this->controller, $url[1])){
$this->method =$url[1];
unset($url[1]);
}
}
$this->params = array_values($url);
call_user_func_array([$this->controller, $this->method],$this->params); //this is line 33
}
/**
* splitURL gets url from browser and processes against the conroller classes and their methods
* #return array
*/
private function splitURL(){
//check if the the GET is set otherwise set the url to defualt class home
$url = isset($_GET['url']) ? $_GET['url'] :"home";
// return explode("/",filter_var(trim($_GET['url'],"/"), FILTER_SANITIZE_URL));
return explode("/",filter_var(trim($url,"/"), FILTER_SANITIZE_URL));
}
}
?>
The Database class's read function is as follows. This method isn't directly referred in the error message
public function read($query, $data = []){
$stmt = self::$conn->prepare($query);
$result = $stmt->execute($data);
if($result){
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(is_array($data) && count($data) > 0){
return $data;
}
}
return false;
}
As I mentioned earlier, this error fires on a live server but the website runs smooth in dev environment with PHP 7.4, Apache2, MySQL 8 Windows 10.
Your help is match appreciated in advance.
I learned this the hard way and I hope this can help someone with similar issues. The cause of the error because of how windows and Linux deals with case sensitivity in file names. In Windows, file names aren't case sensitive while in Linux - they are. So, that was the reason why the website was running smooth in the local dev environment(Windows machine) but throwing an error on a live server(which is Linux). To see the difference, refer to my earlier comment in this thread.
protected function loadModel($model){
if(file_exists("../app/models/". strtolower($model) . ".class.php")){
include "../app/models/".strtolower($model).".class.php";
return $model = new $model();
}else{
return false;
}
}
}
In the "include" line, you can see that I added the strtolower function to include the proper model and that solved the issue.
I have this error with Zend (v1) XmlRpc client :
Uncaught exception 'Zend_XmlRpc_Client_FaultException' with message 'Failed to parse response'.
It's the error status 651.
The call never reaches the class/method requested, it seems that the call is not fired like it was blocked or something. I'm in debug on the method called and it's not triggered.
PHP version is 5.4.
EDIT
Here is the code :
Caller class :
require_once 'library/Zend/XmlRpc/Client.php';
class FrontService
{
private $client;
public function __construct($xmlRpc)
{
$this->client = new Zend_XmlRpc_Client($xmlRpc);
}
public function call($name, $params = array())
{
return $this->client->call($name, $params);
}
}
Call to the class :
$this->_fs = new FrontService(HM_Config::getParam("amf-url"));
$editos = $this->_fs->call('getEdito',$params_home);
Code called :
include_once realpath(dirname(__FILE__) .'/..')
.'/application/bootstrap.php';
require_once '_config.php';
require_once 'DirectDbConnectionV2.php';
class FrontGateway extends DirectDbConnectionV2
{
public static $smStatic;
function __construct()
{
mysql_query("SET NAMES 'utf8'");
$this->sm = self::$smStatic;
$this->log = new Log();
$this->log->set_file('amfDbConnection');
$this->log->write('construct bordel');
}
}
FrontGateway::$smStatic = $sm;
$controllerManager = $sm->get('EditoWebsiteMVC\ControllerManager');
$controllerManager->run('EditoWebsite\Controller\UIGateway', 'xmlRpc');
Code that should be executed :
namespace EditoWebsite\Controller;
use EditoWebsiteMVC\AbstractController;
use EditoWebsiteMVC\ViewRender\CLI as CLIViewRender;
use EditoWebsiteMVC\ViewRender\HTMLTemplate as HTMLTemplateViewRender;
use Zend_XmlRpc_Server as XmlRpcServer;
class UIGatewayController extends AbstractController
{
public function xmlRpcAction()
{
$svr = new XmlRpcServer();
$svr->setClass('FrontGateway');
echo $svr->handle();
exit;
}
}
The code in the getEdito method from the DirectDbConnectionV2 is never reached.
Is there something I need to enable on the server ? or a port that I need to open ?
EDIT EDIT
I should mention that the code is working on another server that I've access to, is there anything I should compare / check to maybe solve that issue ?
Thanks a lot
I don't think there's enough info to even make a guess, but let me try.
I've faced similar issue, where requests sent never reached the server. It turned out to be that Zend_Http_Client_Adapter_Socket adapter is binding to an IPv6 and due to routing issues request never got to the server.
In the end, what solved the issue was:
$client->getAdapter()->setStreamContext(array(
'socket' => array('bindto' => '0:0'),
));
where $client is an instance of Zend_Http_Client.
Again, it's just a shot in the dark, but could be worth trying. :)
Edit:
In your case, you should add following to FrontService constructor:
$this->client->getHttpClient()->getAdapter()->setStreamContext(array(
'socket' => array('bindto' => '0:0'),
));
Edit Edit:
Since back on 1.9.0 there's no getAdapter on Zend_Http_Client, you have to create adapter yourself and pass it to http client:
public function __construct($xmlRpc)
{
$this->client = new Zend_XmlRpc_Client($xmlRpc);
$adapter = Zend_Http_Client_Adapter_Socket();
$adapter->setStreamContext(array(
'socket' => array('bindto' => '0:0'),
));
$this->client->getHttpClient()->setAdapter($adapter);
}
Cheers.
I am new to yii2 and I have created a form, however it is showing the following error while loading the page:
Unknown Method – yii\base\UnknownMethodException
Calling unknown method: yii\web\Request::post()
The code in studController
public function actionStudform()
{
$data = Stud::find()->asArray()->all();
$model = new Stud;
if(($model->load(Yii::$app->request->post())) && $model->validate())
{
echo "validate";
}
else
{
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
}
ok
i also faced that problem and i had sorted out also
in yii2 you have to check that if form is posted or not ?
if form posted then you have to fetch data or print data
try my code it working in my case with same error
public function actionStudform()
{
$data = Stud::find()->asArray()->all();
$model = new Stud;
$request = Yii::$app->request;
if($request->isPost)
{
if(($model->load($request->post)) && $model->validate())
{
print_r($request->post['Stud']);
}
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
else
{
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
}
Check namespace use Yii in your controller
OR
I think this is again the composer dependency resolver doing unexpected things:
you require yiisoft/yii2 in your composer.json but do not have the composer asset plugin installed.
then the dependency resolver does not find packages with vendor bower-asset so it looks for other versions of yiisoft/yii2 that do not have conflict
The result is to install the beta version of yii2 to be installed
The correct solution as already mentioned is to install the composer-asset-plugin:
php composer.phar global require "fxp/composer-asset-plugin:1.0.*#dev"
I have a Zend2 project running on my localhost with no problems. The app runs perfect. I Uploaded it to my server and now it gets a fatal error but not every time.
Sometimes it says this,
Fatal error: Class name must be a valid object or a string in /home/public_html/vendor/zendframework/zend-stdlib/src/ArrayObject.php on line 230
public function getIterator()
{
$class = $this->iteratorClass;
return new $class($this->storage); // line 230
}
And sometimes it says this,
File
/vendor/zendframework/zend-stdlib/src/ArrayObject.php:184
Message:
Passed variable is not an array or object, using empty array instead
Never both and sometimes it loads perfectly with no problems. The file it references is in the vendor path this is the link,
public function exchangeArray($data)
{
if (!is_array($data) && !is_object($data)) {
throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead');
} // Line 184
if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) {
$data = $data->getArrayCopy();
}
if (!is_array($data)) {
$data = (array) $data;
}
$storage = $this->storage;
$this->storage = $data;
return $storage;
}
Any ideas why this would happen on a live server with a zend site but not on a localhost?
I found this post on github which I think it related to ZFCUser
Git Hub Post
Someone in the comments says this,
This issue is caused by the layout.phtml when there is an error. The layout needs to render but it doesn't have $this->url
I have no clue what he is talking about. Is anyone able to shoot me in the right direction?
I'm having a problem loading modules inside my template library in CodeIgniter HMVC. The reason I want to load a module in the template library is that I wish to use modules for sideboxes and other content boxes in my template.
PS: I am also using the Smarty template parsing system for CodeIgniter, but I doubt it has anything to do with the errors, but if you have reasons to believe otherwise, please, let me know.
What I tried to do
I tried to load the module in two different ways, and both presented with the same errors.
The errors
A PHP Error was encountered
Severity: Notice
Message: Undefined Property CI::$template
File: MX/Loader.php
Line Number: 141
-
A PHP Error was encountered
Severity: Notice
Message: Undefined Property CI::$template
Filename: MX/Controller.php
Line number: 57
-
Fatal error: Call to a member function load_content() on a non-object in E:\Xampp\htdocs\firecms\application\modules\sidebar_login_box\controllers\sidebar_login_box.php on line 7
The undefined "load_content()" function will be explained further down (in Sidebar Controller).
The Error lines
MX/Loader
/*Line 140*/if (isset($this->_ci_classes[$class]) AND $_alias = $this->_ci_classes[$class])
/*Line 141*/ return CI::$APP->$_alias;
MX/Controller
/*Line 56*/public function __get($class) {
/*Line 57*/ return CI::$APP->$class;
How I tried to load the modules
This was my first attempt (loading the file and instancing its class):
class Template {
//[...]
public function load_sidebars()
{
$sidebars = $this->CI->cms_model->get_sidebars();
foreach ($sidebars as $sidebar)
{
if (trim($sidebar["content"]) == "")
{
//An example of sidebar module name is "sidebar:login_box"
//The function below changes the name to "sidebar_login_box" (the
//module's folder and controller name.
$module = str_replace(':', '_', $sidebar["module"]);
$file_path = APPPATH.'modules/'.$module.'/controllers/'.$module.'.php';
require_once $file_path;
$class = ucfirst($module);
$object = new $class();
$module_data = $object->index();
$this->_section_data["sidebars"][]["content"] = $module_data;
}
else
{
$this->_section_data["sidebars"][]["content"] = $sidebar["content"];
}
}
}
//[...]
}
And this was my second attempt (using the loader function):
public function load_sidebars()
{
$sidebars = $this->CI->cms_model->get_sidebars();
foreach ($sidebars as $sidebar)
{
if (trim($sidebar["content"]) == "")
{
$module = str_replace(':', '_', $sidebar["module"]);
$this->CI->load->module($module);
$module_data = $this->CI->$module->index();
$this->_section_data["sidebars"][]["content"] = $module_data;
}
else
{
$this->_section_data["sidebars"][]["content"] = $sidebar["content"];
}
}
}
The sidebar controller
This is how the sidebar controller looks like:
class Sidebar_login_box extends Fire_Controller {
public function index()
{
$view_data = array();
//The load_content function in the template library is used to parse template files
//and return them as a string.
return $this->template->load_content("login_box", $view_data);
}
}
The Fire Controller
The Fire_Controller is my core controller. My core classes' prefix is Fire_ instead of MY_.
This is how the fire controller looks like:
class Fire_Controller extends MX_Controller {
public function __construct()
{
parent::__construct();
//Load configurations from the database.
$this->config->load_db_configs();
//Set the timezone.
date_default_timezone_set(config_item("timezone"));
//Loads the form validation library.
$this->load->library("form_validation");
//Reset the Form Validation CI Object (to fix problems with HMVC CI).
$this->form_validation->CI =& $this;
//To reduce load time, the template library will not be loaded in ajax
//requests.
if ( ! $this->input->is_ajax_request())
{
$this->load->library("template");
}
//Force access via SSL connection (HTTPS) if necessary.
if ((int)config_item('force_https') === 1)
{
force_https();
}
}
Note: This is a very recent project of mine, which means that the framework and all third party extensions are in the most recent stable version as of January 06, 2015.
Thank you for your time,
Best regards.
Fixed.
The sidebars were loaded from the set_defaults() method, which was called by the constructor method in my template library. And since it wasn't fully loaded, the template object was not saved in CI's super object, thus being inaccessible and throwing the errors in the sidebar module.
I have moved the set_defaults() call to the render_page() function of my template library (which are called by the modules' controllers), and now it's working perfectly.
Too bad I added bounty a few hours before finding the solution, hehe.
You need to load the library before you can use it in the sidebar controller. It isn't being passed from the parent. Try this:
class Sidebar_login_box extends Fire_Controller {
public function index()
{
$view_data = array();
$this->load->library('template');
//The load_content function in the template library is used to parse template files
//and return them as a string.
return $this->template->load_content("login_box", $view_data);
}
}
Cheers!