system
(system)
May 5, 2009, 10:37pm
1
Hello -
I recently made a post in another thread inquiring about how to access core models (outside the modules directory) from within the modules directory
basically, the project has a Users model which is not confined to only one of my modules, but is used project-wide
for example - one of my modules saves a 'created-by' value into its model, and needs to consult the core Users model to find this value -
Can anybody give direction?
Is this a path issue? or is it a module configuration issue?
system
(system)
May 5, 2009, 10:40pm
2
Also for the record:
The general types of errors that I am getting are of the ‘CWebApplication.Users’ is not defined variety when i try to access them from within the module
Outside the module, the same means to access these models works fine
system
(system)
May 5, 2009, 11:17pm
3
i'm thinking i have to somehow load these models into the module??
system
(system)
May 6, 2009, 12:41am
4
well - i got something working, but i dont like how i did it
i copied all my other mvc's into the module and voila - my module started working
these seems to be a bit redundant - would love to know how i could call those objects without having to do something like this (for obvious reasons)
please let me know if there is a way to avoid having to do this copy hack job
thanks
Peace
hi
I don't seem to have your problem
how are you calling your models ?
MyModel::model()->findAll();
??
system
(system)
May 6, 2009, 1:37pm
6
Quote
hi
I don't seem to have your problem
how are you calling your models ?
MyModel::model()->findAll();
??
yup - thats exactly what i am doing -
i noticed another post in a different thread today that mentioned something along the lines of
'if you are using models across different models you should put them in the applications directory'
would this be what i would need to do as well then?
and if so - how would i go about accomplishing this?
would it change how i am calling these models in general if i moved them elsewhere?
thanks for the help
** edit - i found the quote:
Quote
You will need to use Yii::app()->getModule($name) to generate the module instance first so that its init() can be executed.
Since you are sharing models among modules, it would better if you move those models to the application folder.
please advise
system
(system)
May 6, 2009, 4:09pm
7
if i am missing something obvious - please let me know that as well
it wouldnt be the first time
you can leave a short response that says something like:
"youre a idiot"
my feelings wouldnt be hurt
thanks
qiang
(Qiang Xue)
May 6, 2009, 4:22pm
8
It seems my response was meant for another post?
Would you please elaborate how you get this error? "CWebApplication.Users' is not defined". Are you trying to access Yii::app()->Users?
Nope, we never laugh at people who raise questions.
The problem is that sometimes a question is raised without giving enough details, and thus it makes people trying to guess what is the real problem.
system
(system)
May 6, 2009, 4:30pm
9
Quote
It seems my response was meant for another post?
Would you please elaborate how you get this error? "CWebApplication.Users' is not defined". Are you trying to access Yii::app()->Users?
Nope, we never laugh at people who raise questions.
The problem is that sometimes a question is raised without giving enough details, and thus it makes people trying to guess what is the real problem.
yes - that is exactly what i am trying to do
from my Module, i am trying to access Yii::app()->Users
2 contexts:
i am trying to display contents from the Users model in one of my module views
in my module, i have a create method, and i need to set the author_id using the id of the user who is currently logged in
let me know any and all other details you may need - the help is appreciated
(and yes - i pulled that quote from another thread in the forum, but it seemed somehow applicable for this)
qiang
(Qiang Xue)
May 6, 2009, 4:35pm
10
Why you are accessing Yii::app()->Users if the app doesn't have 'Users' property or app component defined? Are you trying to use 'Users' class that is under app's models directory? If so, you may simply reference Users::model().
system
(system)
May 6, 2009, 5:01pm
11
Quote
Why you are accessing Yii::app()->Users if the app doesn't have 'Users' property or app component defined? Are you trying to use 'Users' class that is under app's models directory? If so, you may simply reference Users::model().
aha - nice - that solved my problem #2
i successfully sent a value to the database with that
but this still does not work (problem #1 ):
<?php
$static = Users::model()->findByPk(2);
$this->renderPartial('/users/_show',array(
'static'=>$static,
));
?>
attempting to display a particular entry in a _show view i created in the users view directory (not inside the module)
thanks for the help
will
(Phpwindcn)
May 6, 2009, 5:20pm
12
Quote
Quote
Why you are accessing Yii::app()->Users if the app doesn't have 'Users' property or app component defined? Are you trying to use 'Users' class that is under app's models directory? If so, you may simply reference Users::model().
aha - nice - that solved my problem #2
i successfully sent a value to the database with that
but this still does not work (problem #1 ):
<?php
$static = Users::model()->findByPk(2);
$this->renderPartial('/users/_show',array(
'static'=>$static,
));
?>
attempting to display a particular entry in a _show view i created in the users view directory (not inside the module)
thanks for the help
You need to put you view files under module's views folder, unless you specified a different view path explicitly
system
(system)
May 6, 2009, 5:32pm
13
ahh interesting - thanks man - i'll test this out
system
(system)
May 6, 2009, 5:58pm
14
Quote
Quote
Quote
Why you are accessing Yii::app()->Users if the app doesn't have 'Users' property or app component defined? Are you trying to use 'Users' class that is under app's models directory? If so, you may simply reference Users::model().
aha - nice - that solved my problem #2
i successfully sent a value to the database with that
but this still does not work (problem #1 ):
<?php
$static = Users::model()->findByPk(2);
$this->renderPartial('/users/_show',array(
'static'=>$static,
));
?>
attempting to display a particular entry in a _show view i created in the users view directory (not inside the module)
thanks for the help
You need to put you view files under module's views folder, unless you specified a different view path explicitly
A+
thanks guys - i recognize the errors in my ways now
Peace