Gii

654 views
Skip to first unread message

Decler

unread,
Jun 20, 2011, 6:49:46 PM6/20/11
to YiiMongoDbSuite
Hi, I have problem with MongoModel Generator

When I want generate model from MongoDB, I receive error


2011/06/21 01:41:21 [error] [exception.CException] exception
'CException' with message 'Property "EMongoDB.tablePrefix" is not
defined.' in /home/www/yii/1.1.7/base/CComponent.php:131
Stack trace:
#0 /home/www/dev/protected/extensions/YiiMongoDbSuite/gii/mongoModel/
MongoModelCode.php(58): CComponent->__get('tablePrefix')
#1 /home/www/yii/1.1.7/web/CFormModel.php(40): MongoModelCode->init()
#2 /home/www/yii/1.1.7/gii/CCodeGenerator.php(149): CFormModel-
>__construct()
#3 /home/www/yii/1.1.7/gii/CCodeGenerator.php(61): CCodeGenerator-
>prepare()
#4 /home/www/yii/1.1.7/web/actions/CInlineAction.php(50):
CCodeGenerator->actionIndex()
#5 /home/www/yii/1.1.7/web/CController.php(300): CInlineAction-
>runWithParams(Array)
#6 /home/www/yii/1.1.7/web/CController.php(278): CController-
>runAction(Object(CInlineAction))
#7 /home/www/yii/1.1.7/web/CController.php(257): CController-
>runActionWithFilters(Object(CInlineAction), Array)
#8 /home/www/yii/1.1.7/web/CWebApplication.php(328): CController-
>run('')
#9 /home/www/yii/1.1.7/web/CWebApplication.php(121): CWebApplication-
>runController('gii/mongoModel')
#10 /home/www/yii/1.1.7/base/CApplication.php(155): CWebApplication-
>processRequest()
#11 /home/www/dev/public/index.php(13): CApplication->run()
#12 {main} REQUEST_URI=/gii/mongoModel

How can I resolv this problem?

Dave Koston

unread,
Jul 21, 2011, 4:15:52 PM7/21/11
to YiiMongoDbSuite
I get the same issue if I define the mongodb connection as 'db' =>
array(), in main.php rather than 'mongodb' => array(),.

In my case, defining as 'mongodb' => array(), gives me the error
'CDbConnection.connectionString cannot be empty.'.


What I don't understand is why the code in YiiMongoDbSuite/gii/
mongoModel/MongoModelCode.php references Yii::app()->db and not
Yii::app->mongodb:

public function init()
{
if(Yii::app()->db===null)
throw new CHttpException(500,'An active "db" connection is required
to run this generator.');
$this->tablePrefix=Yii::app()->db->tablePrefix;
parent::init();
}

It's quite possible that our errors are due to a bad connection
string. My changes to main.php:

'import'=>array(
'application.models.*',
'application.components.*',
'ext.YiiMongoDbSuite.*'
),

'mongodb' => array(
'class' => 'EMongoDB',
'connectionString' => 'mongodb://localhost',
'dbName' => 'testdb',
'fsyncFlag' => false,
'safeFlag' => false,
'useCursor' => false
),

Anyone have some insight on this? I can't find anywhere in the
extension that Yii->app()->db is being set to mongodb.


Thanks!

Ton Yeung

unread,
Nov 9, 2011, 12:47:15 AM11/9/11
to yiimong...@googlegroups.com
Old google groups didn't let me reply to post, so I replied to one of the members instead. Sorry about that.
Is there any resolution to this problem? I'm running into it as well.

Ton
PS: http://www.yiiframework.com/forum/index.php?/topic/19470-installing-yiimongodbsuite-help-please/page__gopid__123346#entry123346 is a bump to a post with a similar issue.

Attila Nagy

unread,
Nov 9, 2011, 3:35:07 AM11/9/11
to yiimong...@googlegroups.com

Hi,

I don't use gii at all, so my answer is just a 'best guess'. I believe
that the gii part of the ymds uses app->db to be compatible with other
gii parts, since gii was designed to work with CActiveRecord, which by
default is the 'db' component.

The core classes of ymds are independent of the component they are
defined in, so if you don't want to use the 'db' component for
something else (eg for a relational db connection), you're free to
define it as 'db' instead of as 'mongodb'.

I didn't try so far using mongodb on the 'db' component, so you might
need to issue an
[classname]::model()->setMongoDBComponent(Yii::app()->db) for each
class to register the different component.

Or, I'd prefer just to set both the 'db' and 'mongodb' components with
the correct configuration. Unused components won't be instantiated
anyway.

Your connection string seems ok to me.


--
Nagy Attila Gabor

Ton Yeung

unread,
Nov 9, 2011, 12:08:28 PM11/9/11
to YiiMongoDbSuite
Thanks for the reply.

I think it might be an issue with the disconnected development
environment.
I've installed the php driver on the vps where mongo is installed, but
not on my xampp machine.
I'll try to install that and see if it makes a difference.

If it doesn't, I'll try adding the connection details for the mysql
database like you suggested.

On Nov 9, 2:35 am, Attila Nagy <nagy.attila.ga...@gmail.com> wrote:
> On Wed, Nov 9, 2011 at 6:47 AM, Ton Yeung <tonyeun...@gmail.com> wrote:
> > Old google groups didn't let me reply to post, so I replied to one of the
> > members instead. Sorry about that.
> > Is there any resolution to this problem? I'm running into it as well.
>
> > Ton
> > PS:
> >http://www.yiiframework.com/forum/index.php?/topic/19470-installing-y...

Ton Yeung

unread,
Nov 9, 2011, 1:09:54 PM11/9/11
to YiiMongoDbSuite
OK, for anyone else who has this problem, you DO need a 'db'
component.
From the requirements, it seems the gii mongomodel generator is made
to ONLY convert db tables to mongo collections.
You cannot use it to create a new model from scratch.

After I added the db component, and ran the model generator, it
worked.
However, it will fail if you don't have the table created in mysql
first (only tested on mysql).
I created the table in mysql and then ran the generator again and
success!

One more thing! Running the CRUD generator throws a "failed to open
stream: no such file or directory windows" in mongo.php.
That's because I didn't install the mongo driver on my webserver, but
on my database server.
Installing the windows driver from GIT link in mongodb didn't make a
difference, but installing the version from the Installation
Docs(php.net) VC6 ThreadSafe did the trick.
Reply all
Reply to author
Forward
0 new messages