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"
Related
A while back I completed this series of tutorials and converted the jobeet from symfony 1 to symfony 2.
http://intelligentbee.com/blog/2013/08/07/symfony2-jobeet-day-1-starting-up-the-project/
I am now trying to upgrade it to 2.8
Everything works except for the lucene search.
I am attempting to implement EWZSearchBundle as a solution.
config.yml
ewz_search:
indices:
indexJob:
path: %kernel.root_dir%/EwzLuceneIndices/%kernel.environment%/myIndexJob
analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\Utf8\CaseInsensitive
# deprecated
analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
path: %kernel.root_dir%/cache/%kernel.environment%/lucene/index
search action in controller
public function searchAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$query = $this->getRequest()->get('query');
if(!$query) {
if(!$request->isXmlHttpRequest()) {
return $this->redirect($this->generateUrl('ibw_job'));
} else {
return new Response('No results.');
}
}
$jobs = $em->getRepository('AcmeJobeetBundle:Job')->getForLuceneQuery($query);
if($request->isXmlHttpRequest()) {
if('*' == $query || !$jobs || $query == '') {
return new Response('No results.');
}
return $this->render('AcmeJobeetBundle:Job:list.html.twig', array('jobs' => $jobs));
}
}
function in entity repository
static public function getLuceneIndex()
{
$luceneSearchForFooIndex = $this->get('ewz_search.lucene.manager')->getIndex('indexJob');
return $luceneSearchForFooIndex ;
}
The error that I get in app_dev.php
Error: Using $this when not in object context
500 Internal Server Error - FatalErrorException
I know that "$this" is out of context and that is why I am getting the error but I have absolutely no id on how to fix it.
Any help/links to docs/ideas for a solution is greatly appreciated.
Thanks in advance.
Composer Saved the Day
"sonata-project/doctrine-orm-admin-bundle": "2.3.*",
"zf1/zend-search-lucene": "~1.12"
After a day or so of trying to make the other search functions work. I was able to the the zend framework work by adding the specific framework component through composer.
It now all works in 2.8.
I want to use https://github.com/HelloFax/hellosign-php-sdk in Yii2 project so I followed following step
1 ) updated composer.json with "hellosign/hellosign-php-sdk": "3.*#dev" in require section
2) run composer update in CMD (I work with window 7)
so it downloaded required libraries (hellosign-php-sdk and libary) in vendor
3 ) include following code in controller file
$client = new HelloSign\Client('df754dd564e52fb2891a60eb2fea777b5320397********');
$response = $client->getSignatureRequest('f6197945000616b383d4752*****');
if ($response->isComplete()) {
echo 'All signers have signed this request.';
} else {
foreach ($response->getSignatures() as $signature) {
echo $signature->getStatusCode() . "\n";
}
}
Error
Unable to find 'app\controllers\HelloSign\Client' in file: C:\wamp\www\yii2hellosign/controllers/HelloSign/Client.php. Namespace missing?
How to solve this issue, any help ?
the library use psr-0 autoload, so you need to prepend classname with \ , like this:
$client = new \HelloSign\Client('...');
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.
i just installed a new component in my site but when i click on component settings button in the backend i am getting this message:
Fatal error: Call to a member function loadByOption() on a non-object in /mysite.com/administrator/components/com_sigpro/models/settings.php on line 32
the file contains this code:
defined('_JEXEC') or die ;
class SigProModelSettings extends SigProModel
{
protected $extensionID = null;
public function getForm()
{
$option = $this->getState('option');
if (version_compare(JVERSION, '2.5.0', 'ge'))
{
$component = JComponentHelper::getComponent($option);
$this->extensionID = $component->id;
JForm::addFormPath(JPATH_ADMINISTRATOR.'/components/'.$option);
$form = JForm::getInstance($option.'.settings', 'config', array('control' => 'jform'), false, '/config');
$form->bind($component->params);
}
else
{
$component = JTable::getInstance('component');
$component->loadByOption($option);
$this->extensionID = $component->id;
$form = new JParameter($component->params, JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'config.xml');
}
return $form;
}
PS my site is running Joomla 1.7.5 stable version and i cant upgrade it to 2.5 because the site is online and productive some components dont works on version 2.5 .
So i will appreciate it if someone can help me fix this error.
Thanks in advance
you 1.6 needs 1.6 specific modules, components & plugins. You'll need to find a 1.6 compatible version or alternative or check the permissions on /configuration.php
Looks like the table class is not present in your file system. It should have been there in the /mysite.com/administrator/components/com_sigpro/tables folder , somewhere ( may vary depending on the code, but looks like they have not included a custom path ). The class should extends JTable class.
so... I basically follow the practical symfony book, and encountered following problem.
I have properly (i guess) installed sfGuardPlugin, built the models, sqls etc, created user and tried to log in with the username and password entered.
i got the following error message:
Fatal error: Call to undefined method sfGuardUserPeer::retrieveByUsername() in /***/plugins/sfGuardPlugin/lib/validator/sfGuardValidatorUser.class.php on line 53
it looks quite weird to me, because the problematic part of sfGuardValidatorUser class looks like this:
// user exists?
if ($user = sfGuardUserPeer::retrieveByUsername($username))
{
// password is ok?
if ($user->getIsActive() && $user->checkPassword($password))
{
return array_merge($values, array('user' => $user));
}
}
while sfGuardUserPeer has just the empty class:
class sfGuardUserPeer extends PluginsfGuardUserPeer
{
}
that extends PluginsfGuardUserPeer, so i checked it out too:
class PluginsfGuardUserPeer extends BasesfGuardUserPeer
{
public static function retrieveByUsername($username, $isActive = true)
{
$c = new Criteria();
$c->add(self::USERNAME, $username);
$c->add(self::IS_ACTIVE, $isActive);
return self::doSelectOne($c);
}
}
that's the missing function!
so - what is wrong? why doesn't it work?
i have already tried all the solutions found with google, but none of them work :/
finally found it!
the
symfony propel:build-model
task unnecessarily generated the sfGuard classes in the model directory from the schema file located in the plugin directory, while all the classes were already present in the sfGuard folder.
geez, that shouldn't happen in such a well-developed framework and plugin...
Simply put that
public static function retrieveByUsername($username, $isActive = true)
{
$c = new Criteria();
$c->add(self::USERNAME, $username);
$c->add(self::IS_ACTIVE, $isActive);
return self::doSelectOne($c);
}
Code into your sfGuardUserPeer class, this will sort out the issue, I did the same when I got this error, it worked for me..