-2

I'm trying to create an if else string on a php of prestashop,

I'm trying to make my site to run a code if the page is discount but run the other code if it is not... but dreamweaver says there are errors, what's wrong in it?

Thank you

this is the code

if ($page_name == 'discount')
{
 public static $definition = array(
    'table' => 'address',
    'primary' => 'id_address',
    'fields' => array(
        'id_customer' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_manufacturer' =>    array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_supplier' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_warehouse' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_country' =>        array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => false),
        'id_state' =>            array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
        'alias' =>                array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
        'company' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
        'lastname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
        'firstname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
        'vat_number' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
        'address1' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => false, 'size' => 128),
        'address2' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
        'postcode' =>            array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
        'city' =>                array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => false, 'size' => 64),
        'other' =>                array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
        'phone' =>                array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
        'phone_mobile' =>        array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
        'dni' =>                array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16),
        'deleted' =>            array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
        'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
        'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
    ),
);
}

else
{
     public static $definition = array(
    'table' => 'address',
    'primary' => 'id_address',
    'fields' => array(
        'id_customer' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_manufacturer' =>    array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_supplier' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_warehouse' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
        'id_country' =>        array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
        'id_state' =>            array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
        'alias' =>                array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
        'company' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
        'lastname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
        'firstname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
        'vat_number' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
        'address1' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
        'address2' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
        'postcode' =>            array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
        'city' =>                array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
        'other' =>                array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
        'phone' =>                array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
        'phone_mobile' =>        array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
        'dni' =>                array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16),
        'deleted' =>            array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
        'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
        'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
    ),
);
}
Marwane
  • 189
  • 2
  • 14
  • 1
    You can't define class properties using if else, not to mention that you can't define class properties using dynamic values. Use a [setter](http://stackoverflow.com/questions/1568091/why-use-getters-and-setters) – Andrei Sep 26 '16 at 09:54
  • Also, when asking a question it is better to always provide the error message if there is one. – BVengerov Sep 26 '16 at 09:55
  • What you could do is, Make your class property as `public static $definition = [];`. In your constructor you can check your `if` condition and populate value for `$definition` – masterFly Sep 26 '16 at 09:57

1 Answers1

2

You can't define a public static member like that. You declare it in the class then initialize it in the method:

class X {
    public static $definition;
    function method()
    {
        if ($page_name == 'discount') {
            $definition = array (
...
            );
        }

        else {
            $definition = array (
                            'table' => 'address',
                            'primary' => 'id_address',
                            'fields' => array (
Dominique Lorre
  • 1,168
  • 1
  • 10
  • 19
  • so i decide a class name then where there are the three dots i put my code? – Marwane Sep 26 '16 at 10:08
  • The three dots mean I have removed some of your code to avoid a long message. Why are you using public static if you are not in a class? – Dominique Lorre Sep 26 '16 at 10:12
  • i basically lnow nothing of php but i need to make some required fields not required only on that discount page so i was tring to use an if on my localhost... so that code is already complete or ihave to add something? – Marwane Sep 26 '16 at 10:15
  • Ask someone who knows php or learn at least some basics. You need to know what is a class before making such changes. – Dominique Lorre Sep 26 '16 at 10:21
  • 3
    You should hire a professional if it's really important. – Dominique Lorre Sep 26 '16 at 10:52