[swagger-codegen][php-symfony] No entrypoint in generated code? - php

I am attempting to generate a php-symfony server stub using swagger-codgen but I am not getting an index.php (or app.php or anything like that).
When I generate a server stub using the php-silex preset I get an index.php. If I google "silex .htaccess" I can easily find the mod_rewrite directives to get it working. However, when I generate code using the php-symfony preset I cannot find the entry point.
I attempted to combine the php-silex and php-symfony generated codebases (since silex is a symfony project) like so:
(index.php):
use Swagger\Server\Controller\GetTypesListController;
$app->GET('/image/list/types', function (Application $app, Request $request) {
$tlc = new GetTypesListController();
$response = $tlc->getTypeListAction($request);
return $response;
//new Response('How about implementing getTypeList as a GET method ?');
});
However, then I get errors like:
"Fatal error: Uncaught Error: Call to a member function getApiHandler() on null"
I modified the getApiHandler function of my generated GetTypesListController to instantiate the apiServer variable:
public function getApiHandler()
{
if (!isset($this->apiServer)){
$this->apiServer = new \Swagger\Server\Api\ApiServer();
}
return $this->apiServer->getApiHandler('getTypesList');
}
but this just gave me another error:
Undefined property: Swagger\Server\Controller\GetTypesListController::$container
(referencing SymfonyBundle-php/Controller/Controller.php on line 149)
I am obviously doing something wrong. I would really appreciate being pointed in the right direction.
Edit: I do realize that I'm not supposed to call controllers inside controllers.. I assume that I'm not supposed to combine these two generated codebases at all.

Related

How to call functions in other PHP files?

I am trying to call a function from one file to another in PHP, however, I am getting the following error:
Fatal error: Call to undefined method SQLite3::print_model_query_form()
I have two files. The first - dbfunctions.php contains the method print_model_query_form().
The second file query_models contains the following code:
include_once("functions/dbfunctions.php");
$db = new SQLite3('D:\xampp\sim\htdocs\dis_sqlite_database\disSQL3.db');
print $db->print_model_query_form("query_models.php");
The function looks a little like this:
function print_model_query_form($action, $current_values = 0){
$db = new SQLite3('D:\xampp\sim\htdocs\dis_sqlite_database\disSQL3.db');
if($current_values){
// set to previous values.
}else{
// get POST values.
}
// Code to print query form.
}
Thanks in advance for any help.
Since you only hit fatal error on 3rd line, $db should be instantiated successfully. So, the issue should be the print_model_query_form method.
Referring to PHP:SQLite3 - Manual
, there is no such built in method called print_model_query_form.
[Edit 1]
Try to use require_once instead of include_once to make sure you have included dbfunctions.php successfully.
[Edit 2]
Check If you are using PHP's built in SQLite3 class (check your php.ini for extension=php_sqlite3.dll or extension=php_sqlite3.so).
If this is the case, check your dbfunctions.php for:-
class Something
new SQLite3
function print_model_query_form
If all the above exists then you should replace your 2nd line with,
$db = new Something(..);
Note: It would be better if you can show dbfunctions.php instead or letting us make assumptions based on guessing.

Error notices using Linkedin Plugin in Cakephp

I am trying to put a Linkedin plugin in cakephp, using this tutorial http://excellencetechnologies.co.in/Telephonia/blog/linked-login-integration-in-cakephp/
Everything works fine until I login in linkedin but after that I get directed to a page with just this two errors:
Notice (8): OAuthRequest::from_consumer_and_token(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "OAuthToken" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition [APP\Plugin\Linkedin\Vendor\OAuth\OAuth.php, line 316]
Notice (8): OAuthSignatureMethod_HMAC_SHA1::build_signature() [oauthsignaturemethod-hmac-sha1.build-signature]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "OAuthToken" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition [APP\Plugin\Linkedin\Vendor\OAuth\OAuth.php, line 126]
I can't find what may be causing them anywhere online so I was wondering if anyone here might know what is causing this.
Wherever in the code the plugin is pulling the access token from session like this:
$accessToken = $this->Session->read($this->sessionAccess);
It is pulling the token in the form of __PHP_Incomplete_Class object. To correct this problem you would have to unserialize the $accessToken like this:
$accessToken = $this->Session->read($this->sessionAccess);
$accessToken = unserialize (serialize ($accessToken));
I did it at the three spots in the code to correct it.
Hopefully it will work for you as well.

Fatal error: Call to undefined method Zend_XmlRpc_Value::getGenerator() magento

I was upgrading magento when something went wrong and now when I try to login to admin, I am unable to log in to back end admin of magento and I get the following error
Fatal error: Call to undefined method Zend_XmlRpc_Value::getGenerator() in /home/boutique/public_html/app/code/core/Zend/XmlRpc/Request.php on line 413
and the code on respective lines is
/**
* Create XML request
*
* #return string
*/
public function saveXml()
{
$args = $this->_getXmlRpcParams();
$method = $this->getMethod();
$generator = Zend_XmlRpc_Value::getGenerator();
$generator->openElement('methodCall')
->openElement('methodName', $method)
->closeElement('methodName');
I cant understand why this issue is happening, I tried replacing request.php and response.php files from fresh download of magento..
can body help me? why this eror is popping?
There's something about your installation of PHP and Magento that's broken — for some reason the Zend_XmlRpc_Value object that's instantiated doesn't contain a getGenerator method. The class for this object is normally defined in
lib/Zend/XmlRpc/Value.php
However, it's possible there may be a class override in place at
app/code/core/Zend/XmlRpc/Value.php
app/code/community/Zend/XmlRpc/Value.php
app/code/local/Zend/XmlRpc/Value.php
It's also possible your system may have another version of the zend framework installed somewhere in the PHP include path.

Instantiating a new PHPCrawl Class throws the error "Call to undefined method stdClass::receivePage()"

I use a foreach loop to loop through multiple seed urls. During each loop, I instantiate a crawler using PHPCrawl and the next seed url.
foreach($companyUrls as $companyId => $companyUrl) {
$crawler = new MyCrawler($companyUrl, $companyId);
$crawler->go();
}
It runs fine for the first loop, but throws the following error the second time through before any crawling has been done:
"Call to undefined method stdClass::receivePage() in
/data/utilities/PHPCrawl_070/classes/phpcrawler.class.php on line 201"
I have not modified the original PHPCrawl V0.70 classes in any way. I have only extended the PHPCrawler class and added process code to the handlePageData() function as described in the PHPCrawl documentation. If I run this without the foreach loop (instantiating a new class one at a time with new urls), the system works fine.
Please help!!
This is a known error and has been fixed in Version 0.71 (I was using version 0.70).
Thanks #prodigitalson for your comment.

Fatal error with Custom Magento Module on one server but not the other

I am creating my own custom module in Magento and during testing on a Litespeed server (PHP v5.2.14) I am getting a Fatal Error: Call to a member function batch() on a non-object in ../../../BatchController.php on line 25 that was not appearing during testing on another linux server and a wamp server (PHP v5.2.11).
This one has stumped me. I am guessing it has something to do with the server configuration rather than the code itself. But i am just guessing. I was hoping someone here could tell me.
The only real major difference I could see, aside from the php versions and environment, is that the server that the error is on is using the Suhosin Patch. But would that be something that could cause this?
The line in question is Mage::getModel('mymodule/mymodel')->batch(); which is enclosed in an IF statement. batch() is a public function located in my model file.
If you need more code let me know.
Thanks!
If you get a "non-object" error when calling a model, there's a problem with Magento's attempt to get your model class, and it is returning null. The reasons for this are not always apparent. If this worked identically on a normal LAMP stack, then the problem is most likely not in your code.
My first guess would be that the file does not have the proper permissions. Otherwise, it may have to do with resolving the classname. You could test this temporarily by calling the plugin directly like this:
$obj = new Mynamespace_Mymodule_Model_Mymodel();
$obj->batch();
If this works, then the file is readable, and you will want to go spelunking in the resolution of that classname. If it doesn't work, you have a problem with either autoloading or the declaration of your class.
Hope that helps!
Thanks,
Joe
Break it down.
You've tried to call
Mage::getModel('mymodule/mymodel')->batch();
and PHP told you it tried to call the method batch on a non-object. That means
Mage::getModel('mymodule/mymodel')
isn't returning a Model object the way it's supposed to.
First thing to do is clear out your Magento cache on the server you're having problems with. If your Module's config hasn't been loaded into the global config tree Magento will try to instantiate a Mage_Core_Model_Mymodel, and fail.
Second step is to make sure your module's app/etc/module file is in place.
Third step is to add some debugging (assuming a 1.4 branch) to the method that instantiates your objects and determine why Magento can't create your object
File: app/code/core/Mage/Core/Model/Config.php
...
public function getModelInstance($modelClass='', $constructArguments=array())
{
$className = $this->getModelClassName($modelClass);
if (class_exists($className)) {
Varien_Profiler::start('CORE::create_object_of::'.$className);
$obj = new $className($constructArguments);
Varien_Profiler::stop('CORE::create_object_of::'.$className);
return $obj;
} else {
#throw Mage::exception('Mage_Core', Mage::helper('core')->__('Model class does not exist: %s.', $modelClass));
return false;
}
}
...

Categories