Tuesday, December 3, 2013

why use magic method __toString() if php return varibale data type?

here is the error message ... must return a string value ... just means the return value of __toString() has to be a value of data type string. If $users_class in your example is not intended to be a string value, it has be to converted to a string before returning it.
But when reading the above example, it seems to me that the var $users_class may just not have been initialized yet. In this case change the method __toString() to :
public function __toString() {
    if(is_null($this->users_class)) {
        return 'NULL';
    }
    return $this->user_class;
}
To make the above code working, you'll need to make a change in the smarty code too. Remove the double quotes around the value of the value= attribute.

Saturday, November 30, 2013

Creating Wildcard Sub Domain Using Apache VirtualHost for php

You can't make dynamic subdomains with .htacces
You will need to configure the apache virtual host to accept requests for multiple domains
<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com *.example.com
    DocumentRoot /www/domain
</VirtualHost>
Adding the wildcard subdomain *.example.com, your PHP application will receive
all requests for any
domain below example.com, ie garbage.example.combusted.example.com,
llama.example.com, etc.
At this point, your application will have to determine the validity of the subdomain and
display the appropriate error for unknown subs.
From there, parse the domain for mike.


2down voteaccepted
Wildcard sub-domains are definitely possible using Apache virtual hosts.
I had basically the same requirements and managed to get it working with Apache's mod_vhost_alias.somodule. Try this in your http-vhosts.conf file:
DocumentRoot "/home/admin1/public_html/userweb/" 
<Directory "/home/admin1/public_html/userweb/"> 
    Options None 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
</Directory>

<VirtualHost *:80>
    DocumentRoot /home/admin1/public_html/
    ServerName www.example.com
</VirtualHost>

<VirtualHost *:80> 
    VirtualDocumentRoot /home/admin1/public_html/userweb/%1.example.com/ 
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /home/admin1/public_html/
    ServerName example.com
</VirtualHost>
Note that I haven't tested this, but it's pretty close to the solution that worked for me.