PyroCMS custom libraries and CI SuperObject - codeigniter

It should be simple, but it's not.
I have a library that is hoping to use other libraries, but something ain't jiving.
Both libs live in system/cms/libraries because as far as I can tell, addons/shared_addons/libraries is utterly useless and the libraries need to be autoloaded (it seems that system/cms is essentially system/application but please correct me if wrong). An aside: just for kicks I put a library in shared_addons/libaries just to see if I could call if from a module; I couldn't. Why is it there?
Lib1
-needs db
-needs lib2
Lib2
-needs session
Here's what happens. Controller [module] loads; calls lib1 which calls lib2 which throws an error. Lib1 is to be called by all module controllers. Lib2 uses session data that is set earlier on and is only called by lib1.
In lib2 I use $CI=get_instance() to supposedly enable CI libs (e.g. database, session). However, I can't get past "Fatal error: Call to a member function userdata() on a non-object"; which is called by
//system/cms/libraries/lib2.php
$this->CI =& get_instance();
//$this->load->library('database'); == "can't find class database"
$ekeyLoc = $this->CI->session->userdata('ronery');
now if I run this in a module controller, it works as expected.
So googling that error, a lot of "db not loaded"'s come up. Just to make sure, I tried to load the database, but because eff me, it can't find class 'database' NB: database is being autoloaded.
When you assign CodeIgniter super object, I'm assuming it's grabbing the whole jabloney, right? I thought so. But to make sure, I decided to try and load the database class in a module/controller, which turns out, because eff me, couldn't be found.
I tried looking through the pyroCMS docs to find out about any trickery, but there ain't much, and none helpful to my situation.
Why can't I load a core library from a module controller?
Why can't I load a core library into a custom library in system/cms/libraries?
Why doesn't the CodeIgniter super object I assign contain session/db crap?
Why can't I load a library from /addons/shared_addons/library?
Why would a call to $this->session->userdata() work from a module controller, but not from a library in the system/cms/libraries folder even though CodeIgniter super object has been assigned?
Thanks.
After 2 days with no answer, I find it both frustrating and hilarious that continuing to search for help inevitably leads to this question being the top google result. FML.

First things first:
$this->load->library('database');
That is not valid CodeIgniter code, like their documentation says it should be:
$this->load->database();
As you've already pointed out though this is autoloaded so there is no need to do that anyway.
Why can't I load a core library from a module controller?
You can.
Why can't I load a core library into a custom library in system/cms/libraries?
You can.
Why doesn't the CodeIgniter super object I assign contain session/db crap?
It does.
Why can't I load a library from /addons/shared_addons/library?
This was not possible in 1.3.x but should have been fixed in 1.3.2, if not has been fixed since in 2.0.
I do not know what you are doing or why you are having such problems, but without any example code or a description of what version of PyroCMS you are using I cannot help any further.
If you have been stuck for two days why have you not posted on our forums? If you HAVE posted on our forums (I didn't see anything about it) you should have put a link in this post to your forum thread to help other people answer the questions.
This is not the first time anyone has been stuck on the internet but you act like it is. Come on, you know how this works! :)

Related

Wagtail alongside Django Rest Framework drf-yasg?

I am implementing a Wagtail powered blog within a larger (primarily DRF) driven app. I'm attempting to use drf-yasg for my documentation.
Since installing wagtail, the docs are now throwing
'Request' object has no attribute 'wagtailapi_router'
It looks to be related to the introspection that drf-yasg does, and all I can find about excluding views from drf-yasg is done at the code level. Being an installed module obviously I want to avoid that.
Has anyone got these 2 (3) components playing nicely together?
It's been a very long time since you asked this question, but as I found this while looking for an answer myself, I thought I might share what worked for me.
Note that I'm not using drf-yasg, but rather DRF's own schema generator. They do however have a lot in common.
The problem in my case was that the schema generator URL was defined like this:
path(
"schema/",
get_schema_view(title="My API Schema"),
name="openapi-schema",
),
What I needed to add was a patterns= argument that referenced my API specifically, leaving out the other non-API urls (like Wagtail):
path(
"v3/schema/",
get_schema_view(title="My API Schema", patterns=router.urls),
name="openapi-schema",
),
I hope that helps... someone :-D

Using "check" package causes another package to error

I'm using the Check package to validate parameters passed to Meteor methods. And I'm using Audit argument checks to enforce this.
However, I've added another package, Meteor Tags and when I try to use methods from the Tags package, I get a server error "Exception while invoking method '/patterns/addTag' Error: Did not check() all arguments during call to '/patterns/addTag'".
I think I understand why this error happens - the method in the Tags package doesn't check its inputs, so Audit Argument Checks generates an error. But I can't find any way around this, apart from 1) don't enforce checking, or 2) hack the Tags package methods so they use check. Neither of these seems like a great option - checking server parameters is a good idea, and hacking a package is not very maintainable.
Does anybody know if there is any smart way to use 'Audit argument checks' with packages that provide new server methods? I have looked at the Check documents, and searched online, but I haven't found an answer.
I hope this question makes sense.
Using audit-argument-checks is like saying: "I want to be serious about the security of the methods in my app." It's global to all methods in your app's codebase, including the methods from your installed packages.
There is no way to specify which parts of the app get checked, as that would be the equivalent of saying: "I want to be serious about the security of the methods I've written, but I don't care about the security holes created by some pacakges" (which doesn't make a lot of sense).
Note to package authors
Check your method arguments. It's not hard, and it prevents this situation from happening. Frankly, a package without this basic security really shouldn't be installed in the first place.
What you should do
Unless you have a throwaway app, I wouldn't recommend removing audit-argument-checks. Instead I'd do the following (assuming the package really has something of value):
Open an issue on github and let the maintainer know what's up.
Fork the code, and add the required checks. Keep this version as a local package.
Submit a pull request for the changes.
If all goes well, your PR will be accepted and everyone can benefit from the change. In the worst case, you'll still have a local copy that you can use in your app.

Hidden Laravel Methods (5.1)

First, I have IDE helper, and the php storm plugin. I tried the Gist pre made too. There are some similar questions, but no one seems to get answers. I'll probably poke laracasts and ide helper bug list if I don't get anything here.
So I'm following along to some of the into laracasts, and the guy keeps using methods that are not defined as far as I can tell. Situation:
I created a eloquent model called Article. It extends
Illuminate\Database\Eloquent\Model
So now I have App\Article and I can call any of the methods available to model. For example:
$article = \App\Article::all();
PHPStorm is happy. He keeps pulling stuff like ::find() or ::findOrFail()
It's in the docs
I just don't under stand how that works, I don't see the methods defined in model. If this is what ide helper is supposed to fix, then I'm not certain it's working correctly. I can RTFM, I'm pretty sure I followed the directions to a tee.
Ya know, I just found it. I see this question out and about, so I'll answer it here.
https://github.com/barryvdh/laravel-ide-helper/issues/248#issuecomment-131503475
Fixed find or fail for me. find is still MIA. I'm surprised laravel doesn't support their code base in the forms of plugins or dedicated IDE's bit more. It's all just people out there creating a community and moving the world forward so I can't complain too much.
It works because Model implements __callStatic() which dispatches it to itself on a new instance: __callStatic() implementation on Model
It creates a new instance (new static) of the model in question and dispatches the statically called method on the instance.
Effectively, Model::foo($bar) is the same as (new Model)->foo($bar).

Why does a "on a non-object" error occurs with this extension in Magento?

I'm having an Issue with a blog extension in Magento CE 1.6.2.0.
I installed this extension: Neotheme_nBlog.
I created an entry in the administrator.
Then I went to http://www.example.com/index.php/blog/ to see the recently created entry.
What I saw was an error like this:
Fatal error: Call to a member function getName() on a non-object
in /home/example.com/public_html/app/design/frontend/default/caramel/template/magicat/left.phtml
I searched in google the terms: "template/magicat/left.phtml" getName and what I only found is sites having this issue, but no support at all.
Please note: I know what does that error mean in PHP ("unfortunately" I'm not new at that). What I don't understand is what's happening with such [NON/null] object and how to fix it without killing a dozen of kittens.
Question: What can I do to solve it? What is the nature of the error, regarding Magento?(again: not PHP).
Notes: The Magento site (http://magento.stackexchange.com) is somewhat poor and strict to bring support of such nature, so asking there is not an option.
Edit (as answer to comment, and to clarify):
Neotheme is still not responding the request.
Don't know what should I look on such file (instances are not initialized there, but only accessed).
I'm using the default theme (caramel), which has esthetical changes (does not have layout changes).
It's hard to say without seeing your system specifically, but on this
template/magicat/left.phtml
It looks like you've added a template named magicat/left.phtml to your system -- either via an extension or custom development. Somewhere in this file PHP's called getName on a non-object. There's a variety of reasons this could be happening, and without seeing the specific line of code PHP's complaining about in your system, it's hard to say. It'd also be helpful to know if magicat is part of the extension or something else.
The most common reason for this error in a template is code that relies on a block being there that's been removed by another extension (eitehr via layout XML or observer methods)
$this->getLayout()->getBlock('some_block')->getName();
The next most common is people using the registry to communicate between templates and views, but a registry key not being set
Mage::registry('some_item')->getName();
Without knowing the variable and context, it's doubtful anyone will be able to help you.

how to display all the mothods called in the codeigniter profiler

is there any way to display all the methods called in the codeigniter profiler.
Also like to display which method calls which method and which method trigger the query
Unfortunately, your question is not very clear to me. I am not really sure of what you want to do.
there is a PHP command available in later versions called debug-backtrace.
http://php.net/manual/en/function.debug-backtrace.php
this gives you the stack trace of all commands executed to get to a particular method.
The codeigniter profiler is a system library. If there is a feature you really need it is possible to extend the profiler class to have the functionality you require. the CI manual explains how to do this in the section about 'Extending Native Libraries'

Resources